Csh et bash
Répondre à la discussion
Affichage des résultats 1 à 8 sur 8

Csh et bash



  1. #1
    invite70eda27f

    Csh et bash


    ------

    Salut a tous !

    Je dois installer un programme (IRAF) et puor cela utiliser un fichier csh mais ma console me renvoit l'erreur suivante :
    :bash: irafuser.csh: line 11: syntax error near unexpected token `else'
    :bash: irafuser.csh: line 11: `else if (-f /etc/yellowdog-release || "`uname -m`" == "ppc") then'
    Voici le fichier qui pose probleme :

    Code:
    export OS_MACH=	`uname -s | tr '[A-Z]' '[a-z]' | cut -c1-6`
    if (-f /etc/redhat-release) then
        if (`uname -m` == "ppc") then
    	export MACH= linuxppc
        else
    	export MACH= redhat
        endif
    else if (-f /etc/yellowdog-release || "`uname -m`" == "ppc") then
    	export MACH= linuxppc
    else
        export MACH	=`uname -s | tr '[A-Z]' '[a-z]'`
    endif
    
    if ($MACH == "darwin") then
        # Let the IRAFARCH override the machine to support cross compilation.
        if ($?IRAFARCH) then
            if ("$IRAFARCH" == "macosx") then
    	    export MACH= macosx
            else if ("$IRAFARCH" == "macintel") then
    	    export MACH= macintel
            endif
        else
            if ("`uname -m`" == "i386") then
                export MACH= macintel
                export IRAFARCH= macintel
            else
                export MACH= macosx
                export IRAFARCH= macosx
            endif
        endif
    else if ($OS_MACH == "cygwin") then
        export MACH= cygwin
    endif
    
    export	hostid=	unix
    export	host=	${iraf}unix/
    export	hlib=	${iraf}unix/hlib/
    export	hbin=	${iraf}unix/bin.$MACH/
    export	tmp=	/tmp/
    
    # Default to GCC for compilation.
    export	CC=	gcc
    export	F77=	$hlib/f77.sh
    export	F2C=	$hbin/f2c.e
    export	RANLIB=	ranlib
    
    switch ($MACH)
    case freebsd:
        export HSI_CF= "-O -DBSD -DPOSIX -w -Wunused"
        export HSI_XF= "-Inolibc -/DBSD -w -/Wunused"
        export HSI_FF= "-O"
        export HSI_LF= "-static"
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= "-lcompat"
        set    mkzflags = "'lflags=-z' -/static"
        breaksw
    
    case macosx:
        export CC= cc
        export CC_f2c= cc
        export F2C= $hbin/f2c.e
    
        export HSI_CF= "-O -DMACOSX -w -Wunused -arch ppc"
        export HSI_XF= "-Inolibc -/DMACOSX -w -/Wunused"
        if (`uname -r` == "5.5") then
    	export HSI_CF =	"$HSI_CF -DOLD_MACOSX"
    	export HSI_XF =	"$HSI_XF -DOLD_MACOSX"
        endif
        export HSI_FF= "-O -arch ppc"
        export HSI_LF= "-arch ppc"
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= ""
        set    mkzflags = "'lflags=-z'"
        breaksw
    
    case macintel:
        export CC= cc
        #export F77	gcc
        export CC_f2c= cc
        export F2C= $hbin/f2c.e
    
        export HSI_CF= "-O -DMACOSX -DMACINTEL -w -Wunused -arch i386"
        export HSI_FF= "-O -arch i386"
        export HSI_LF= "-arch i386"
        export HSI_XF= "-Inolibc -/DMACOSX -/DMACINTEL -w -/Wunused"
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        if ($?IRAF_UNIBIN) then
            export HSI_CF= "$HSI_CF -arch ppc -arch i386"
            export HSI_FF= "$HSI_FF -arch ppc -arch i386"
            export HSI_LF= "$HSI_LF"
            export HSI_LFLAGS= "$HSI_LFLAGS -arch ppc -arch i386"
        endif
        export HSI_OSLIBS= ""
        set    mkzflags = "'lflags=-z'"
        breaksw
    
    case linux:
        export HSI_CF "-O -DLINUX -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF "-Inolibc -w -/Wunused"
        export HSI_FF "-O"
        export HSI_LF ""
        export HSI_F77LIBS ""
        export HSI_LFLAGS ""
        export HSI_OSLIBS ""
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    case redhat:
        export HSI_CF= "-O -DLINUX -DREDHAT -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF= "-Inolibc -w -/Wunused"
        export HSI_FF= "-O"
        #export HSI_LF "-Wl,-Bstatic"
        export HSI_L=F ""
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= ""
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    case suse:
        export HSI_CF= "-O -DSUSE -DLINUX -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF= "-Inolibc -w -/Wunused"
        export HSI_FF= "-O"
        #export HSI_LF "-Wl,-Bstatic -specs=/iraf/iraf//unix/bin.suse/gcc-specs"
        export HSI_LF= "-specs=/iraf/iraf//unix/bin.suse/gcc-specs"
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= ""
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    case sunos:
        export HSI_CF= "-O -DSOLARIS -DX86 -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF ="-Inolibc -w -/Wunused"
        export HSI_FF= "-O"
        #export HSI_LF "-t -Wl,-Bstatic"
        #export HSI_LFLAGS "-t -Wl,-Bstatic"
        #export HSI_OSLIBS \
        #	"-lsocket -lnsl -lintl -Wl,-Bdynamic -ldl -Wl,-Bstatic -lelf"
        export HSI_LF= "-t"
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= "-t"
        export HSI_OSLIBS= "-lsocket -lnsl -lintl -ldl -lelf"
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    case linuxppc:
        export HSI_CF= "-O -DLINUX -DREDHAT -DLINUXPPC -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF= "-Inolibc -w -/Wunused"
        export HSI_FF= "-O"
        export HSI_LF= ""
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= ""
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    case cygwin:
        export HSI_CF= "-O -DCYGWIN -DLINUX -DREDHAT -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF= "-Inolibc -w -/Wunused -/DCYGWIN"
        export HSI_FF= "-O"
        #export HSI_LF "-Wl,-Bstatic"
        export HSI_LF= ""
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= "${iraf}unix/bin.cygwin/libcompat.a"
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    default:
        echo 'Warning in hlib$irafuser.csh: unknown platform '"$MACH"
        exit 1
        breaksw
    endsw
    
    # The following determines whether or not the VOS is used for filename mapping.
    if (-f ${iraf}lib/libsys.a) then
    	export	HSI_LIBS\
        "${hlib}libboot.a ${iraf}lib/libsys.a ${iraf}lib/libvops.a ${hlib}libos.a"
    else
    	export	HSI_CF= "$HSI_CF -DNOVOS"
    	export	HSI_LIBS= "${hlib}libboot.a ${hlib}libos.a"
    endif
    
    export HSI_LIBS= "$HSI_LIBS $HSI_OSLIBS"
    
    alias	mkiraf	${hlib}mkiraf.csh
    alias	mkmlist	${hlib}mkmlist.csh
    alias	mkz	${hbin}mkpkg.e "$mkzflags"
    
    alias	edsym	${hbin}edsym.e
    alias	generic	${hbin}generic.e
    alias	mkpkg	${hbin}mkpkg.e
    alias	rmbin	${hbin}rmbin.e
    alias	rmfiles	${hbin}rmfiles.e
    alias	rtar	${hbin}rtar.e
    alias	wtar	${hbin}wtar.e
    alias	xc	${hbin}xc.e
    alias	xyacc	${hbin}xyacc.e
    export OS_MACH=	`uname -s | tr '[A-Z]' '[a-z]' | cut -c1-6`
    if (-f /etc/redhat-release) then
        if (`uname -m` == "ppc") then
    	export MACH= linuxppc
        else
    	export MACH= redhat
        endif
    else if (-f /etc/yellowdog-release || "`uname -m`" == "ppc") then
    	export MACH= linuxppc
    else
        export MACH	=`uname -s | tr '[A-Z]' '[a-z]'`
    endif
    
    if ($MACH == "darwin") then
        # Let the IRAFARCH override the machine to support cross compilation.
        if ($?IRAFARCH) then
            if ("$IRAFARCH" == "macosx") then
    	    export MACH= macosx
            else if ("$IRAFARCH" == "macintel") then
    	    export MACH= macintel
            endif
        else
            if ("`uname -m`" == "i386") then
                export MACH= macintel
                export IRAFARCH= macintel
            else
                export MACH= macosx
                export IRAFARCH= macosx
            endif
        endif
    else if ($OS_MACH == "cygwin") then
        export MACH= cygwin
    endif
    
    export	hostid=	unix
    export	host=	${iraf}unix/
    export	hlib=	${iraf}unix/hlib/
    export	hbin=	${iraf}unix/bin.$MACH/
    export	tmp=	/tmp/
    
    # Default to GCC for compilation.
    export	CC=	gcc
    export	F77=	$hlib/f77.sh
    export	F2C=	$hbin/f2c.e
    export	RANLIB=	ranlib
    
    switch ($MACH)
    case freebsd:
        export HSI_CF= "-O -DBSD -DPOSIX -w -Wunused"
        export HSI_XF= "-Inolibc -/DBSD -w -/Wunused"
        export HSI_FF= "-O"
        export HSI_LF= "-static"
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= "-lcompat"
        set    mkzflags = "'lflags=-z' -/static"
        breaksw
    
    case macosx:
        export CC= cc
        export CC_f2c= cc
        export F2C= $hbin/f2c.e
    
        export HSI_CF= "-O -DMACOSX -w -Wunused -arch ppc"
        export HSI_XF= "-Inolibc -/DMACOSX -w -/Wunused"
        if (`uname -r` == "5.5") then
    	export HSI_CF =	"$HSI_CF -DOLD_MACOSX"
    	export HSI_XF =	"$HSI_XF -DOLD_MACOSX"
        endif
        export HSI_FF= "-O -arch ppc"
        export HSI_LF= "-arch ppc"
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= ""
        set    mkzflags = "'lflags=-z'"
        breaksw
    
    case macintel:
        export CC= cc
        #export F77	gcc
        export CC_f2c= cc
        export F2C= $hbin/f2c.e
    
        export HSI_CF= "-O -DMACOSX -DMACINTEL -w -Wunused -arch i386"
        export HSI_FF= "-O -arch i386"
        export HSI_LF= "-arch i386"
        export HSI_XF= "-Inolibc -/DMACOSX -/DMACINTEL -w -/Wunused"
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        if ($?IRAF_UNIBIN) then
            export HSI_CF= "$HSI_CF -arch ppc -arch i386"
            export HSI_FF= "$HSI_FF -arch ppc -arch i386"
            export HSI_LF= "$HSI_LF"
            export HSI_LFLAGS= "$HSI_LFLAGS -arch ppc -arch i386"
        endif
        export HSI_OSLIBS= ""
        set    mkzflags = "'lflags=-z'"
        breaksw
    
    case linux:
        export HSI_CF "-O -DLINUX -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF "-Inolibc -w -/Wunused"
        export HSI_FF "-O"
        export HSI_LF ""
        export HSI_F77LIBS ""
        export HSI_LFLAGS ""
        export HSI_OSLIBS ""
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    case redhat:
        export HSI_CF= "-O -DLINUX -DREDHAT -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF= "-Inolibc -w -/Wunused"
        export HSI_FF= "-O"
        #export HSI_LF "-Wl,-Bstatic"
        export HSI_L=F ""
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= ""
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    case suse:
        export HSI_CF= "-O -DSUSE -DLINUX -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF= "-Inolibc -w -/Wunused"
        export HSI_FF= "-O"
        #export HSI_LF "-Wl,-Bstatic -specs=/iraf/iraf//unix/bin.suse/gcc-specs"
        export HSI_LF= "-specs=/iraf/iraf//unix/bin.suse/gcc-specs"
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= ""
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    case sunos:
        export HSI_CF= "-O -DSOLARIS -DX86 -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF ="-Inolibc -w -/Wunused"
        export HSI_FF= "-O"
        #export HSI_LF "-t -Wl,-Bstatic"
        #export HSI_LFLAGS "-t -Wl,-Bstatic"
        #export HSI_OSLIBS \
        #	"-lsocket -lnsl -lintl -Wl,-Bdynamic -ldl -Wl,-Bstatic -lelf"
        export HSI_LF= "-t"
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= "-t"
        export HSI_OSLIBS= "-lsocket -lnsl -lintl -ldl -lelf"
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    case linuxppc:
        export HSI_CF= "-O -DLINUX -DREDHAT -DLINUXPPC -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF= "-Inolibc -w -/Wunused"
        export HSI_FF= "-O"
        export HSI_LF= ""
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= ""
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    case cygwin:
        export HSI_CF= "-O -DCYGWIN -DLINUX -DREDHAT -DPOSIX -DSYSV -w -Wunused"
        export HSI_XF= "-Inolibc -w -/Wunused -/DCYGWIN"
        export HSI_FF= "-O"
        #export HSI_LF "-Wl,-Bstatic"
        export HSI_LF= ""
        export HSI_F77LIBS= ""
        export HSI_LFLAGS= ""
        export HSI_OSLIBS= "${iraf}unix/bin.cygwin/libcompat.a"
        set    mkzflags = "'lflags=-Nxz -/Wl,-Bstatic'"
        breaksw
    
    default:
        echo 'Warning in hlib$irafuser.csh: unknown platform '"$MACH"
        exit 1
        breaksw
    endsw
    
    # The following determines whether or not the VOS is used for filename mapping.
    if (-f ${iraf}lib/libsys.a) then
    	export	HSI_LIBS\
        "${hlib}libboot.a ${iraf}lib/libsys.a ${iraf}lib/libvops.a ${hlib}libos.a"
    else
    	export	HSI_CF= "$HSI_CF -DNOVOS"
    	export	HSI_LIBS= "${hlib}libboot.a ${hlib}libos.a"
    endif
    
    export HSI_LIBS= "$HSI_LIBS $HSI_OSLIBS"
    
    alias	mkiraf	${hlib}mkiraf.csh
    alias	mkmlist	${hlib}mkmlist.csh
    alias	mkz	${hbin}mkpkg.e "$mkzflags"
    
    alias	edsym	${hbin}edsym.e
    alias	generic	${hbin}generic.e
    alias	mkpkg	${hbin}mkpkg.e
    alias	rmbin	${hbin}rmbin.e
    alias	rmfiles	${hbin}rmfiles.e
    alias	rtar	${hbin}rtar.e
    alias	wtar	${hbin}wtar.e
    alias	xc	${hbin}xc.e
    alias	xyacc	${hbin}xyacc.e

    (J'ai deja change tous les
    Code:
    setenv a b
    en
    Code:
    export a=b
    .)

    Y'a-t-il une solution pour corriger cette erreur ?

    Merci

    -----

  2. #2
    Philou67

    Re : Csh et bash

    Si tu veux lancer un script csh alors que ton shell par défaut est bash, il faut spécifier à bash que le shell à lancer pour ton script est csh.

    Deux manières pour le faire :
    csh <script>
    ou ajouter la ligne suivante en début de script
    #!/usr/bin/csh

    Le problème que soulève cette méthode est que les variables d'environnement qui sont mises à jour dans le script appelé ne subsistent pas après l'exécution du script.
    En bash, pour qu'un script s'exécute dans l'environnement courant (au lieu d'ouvrir un environnement fils dans un nouveau processus bash), il existe une commande (source ou .) qui permet cela.
    Mais cette méthode n'est pas possible si le script n'est pas un script bash. Il est alors possible de "contourner" ce problème en créant un processus bash fils qui deviendra le processus interractif courant (c'est à dire que dans la liste des processus, il y aura 2 bash, dont seul le dernier disposera des variables d'environnement).
    Pour cela, s'assurer que la variable $SHELL est dans l'environnement
    Code:
    env | grep SHELL
    Si tel n'est pas le cas, l'exporter en ajouter
    Code:
    export SHELL
    dans un fichier d'initialisation comme .bash_profile ou .bash_login

    Puis, ajouter en fin de script csh, la ligne suivante :
    Code:
    exec $SHELL -i
    ce qui aura pour effet que le nouveau shell créé (par $SHELL -i) prendra la place du script csh lancé.

    Mais pour cela, il faut que ta machine possède le shell csh installé bien sur. Dans le cas contraire, il faut porter le csh vers bash, ce que tu proposes avec les setenv... Pour les if, par exemple, le "else if" s'écrit elif...
    En fait, csh et bash sont assez différents. Si tu possède csh sur ta machine, il est préférable de laisser le script intact, à mon avis, et de choisir la première.
    Un exemple de construction if en bash:
    Code:
    if [[ -f /etc/redhat-release ]] ;
    then
        if [[ "`uname -m`" == "ppc" ]];
        then
            export MACH=linuxppc
        else
            export MACH=redhat
        fi
    elif [[ -f /etc/yellowdog-release || "`uname -m`" == "ppc" ]];
    then
            export MACH= linuxppc
    else
        export MACH=`uname -s | tr '[A-Z]' '[a-z]'`
    fi
    :'( Plus j'apprends, et plus je mesure mon ignorance

  3. #3
    invite70eda27f

    Re : Csh et bash

    Merci pour ta reponse Philou, ca marche !

    See you

  4. #4
    Philou67

    Re : Csh et bash

    Ouf !!! j'ai eu chaud.

    Et, tu as choisi quelle solution ?
    :'( Plus j'apprends, et plus je mesure mon ignorance

  5. A voir en vidéo sur Futura
  6. #5
    invite70eda27f

    Re : Csh et bash

    J'ai finalement change mon /bin/bash par un /bin/csh. Mais au moins si je dois convertir du bash en csh, je aurais comment faire

    Merci encore

  7. #6
    Philou67

    Re : Csh et bash

    Tu veux dire que tu as changé ton shell de login ?
    :'( Plus j'apprends, et plus je mesure mon ignorance

  8. #7
    invite70eda27f

    Re : Csh et bash

    Citation Envoyé par Philou67 Voir le message
    Tu veux dire que tu as changé ton shell de login ?
    Ben oui... Il faut pas ? Mais c'etait sur une session particuliere creee juste pour un programme donc c'est pas tres important, mais je suis preneur de conseil...

  9. #8
    Philou67

    Re : Csh et bash

    OK, si ce n'est pas la session de login, je n'ai pas d'avis contraire.
    Mais j'aurai été choqué d'une migration d'un shell de login de bash vers csh... un petit retour à l'antiquité
    :'( Plus j'apprends, et plus je mesure mon ignorance

Discussions similaires

  1. Bash : remplacement de variables
    Par Bruno dans le forum Logiciel - Software - Open Source
    Réponses: 4
    Dernier message: 09/07/2008, 21h15
  2. Commande cd dans un fichier bash
    Par invite70eda27f dans le forum Logiciel - Software - Open Source
    Réponses: 6
    Dernier message: 02/07/2008, 18h32
  3. Probleme arrivée d' eau LV bash
    Par Viki dans le forum Dépannage
    Réponses: 0
    Dernier message: 21/11/2006, 09h33
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...