Find the answer to your Linux question:
Results 1 to 3 of 3
Hi All, U hiope you can be able to help me. I am setting some environmental variable in my .bashrc , the sample code I was provided with is for ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    22

    [SOLVED] bash syntax to translate from csh scripts ..

    Hi All,

    U hiope you can be able to help me.

    I am setting some environmental variable in my .bashrc , the sample code I was provided with is for CSH but I am using bash, and there are some syntax differences between them ... I got most of the script to work, but I am getting an error at this part :

    Code:
    if ($RMSTREE == $RMANTREE) then
         set path=($path $RMANTREE/bin)
     else
         set path=($path $RMSTREE/bin $RMANTREE/bin)
     endif
    the error is:
    Code:
    bash: /home/renderuser/.bashrc: line 40: syntax error near unexpected token `('
    bash: /home/renderuser/.bashrc: line 40: `     set path=($path $RMANTREE/bin)'
    The way to set environmental variables is different between chs and bash, so while csh uses setenv, in bash we use export.

    My guess is that the compound command in brackets has to be expressed differently to work in bash ... does anyone knows how should I translate that ???


    Many thanks fro your help.

    Mahuro
    Last edited by MikeTbob; 01-03-2011 at 05:23 PM. Reason: Added Code Tags

  2. #2
    Linux User Manko10's Avatar
    Join Date
    Sep 2010
    Posts
    250
    Code:
    if [ $RMSTREE == $RMANTREE ]; then
        export path="$path $RMSTREE"
    else
        export path="$path $RMSTREE/bin $RMANTREE/bin"
    fi
    But I guess, you want to set the $PATH environment variable. In this case you have to captialize the variable name ($PATH instead of $path) and separate the values by colons ("foo:bar" instead of "foo bar").
    So the code would be this:
    Code:
    if [ $RMSTREE == $RMANTREE ]; then
        export PATH="$PATH:$RMSTREE"
    else
        export PATH="$PATH:$RMSTREE/bin:$RMANTREE/bin"
    fi
    Refining Linux Advent calendar: “24 Outstanding ZSH Gems

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Posts
    22

    [solved]

    Hi Manko,

    Many thanks that worked !!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...