0

I am writing a simple script to source path variable as below:

#!/bin/csh
echo "setting path"
set path=($path /sbin:/mscc/apps)

However, the path variable does not change and remain the same. The csh shell does not have any errors/warnings.

If I add an invalid line, for example:

setenv PATH $PATH:sbin

It complains "Bad substitute." but the two path above are added. Why is it happening?

  • 2
    Are you executing the sample script and expecting your current (the parent) shell's $path to change? – Jeff Schaller Mar 16 '18 at 17:16
  • Yes, I expect my current opened shell (from GNOME) to change the $path. I tried your answers with both ways and it is not working. The only time it works is when I add an invalid line at the end of the file (eg, like dummy text: ppp). – Allen W Mar 16 '18 at 17:36
  • sourcing the script doesn't change the path? Did you try using a space instead of a colon? – Jeff Schaller Mar 16 '18 at 17:38
  • Yes, to eliminate the concern, I am setting only one path variable now which has the same result. – Allen W Mar 16 '18 at 17:46
  • Can you edit a transcript of your session into your question, showing your initial path, your execution of the script, and the resulting path? – Jeff Schaller Mar 16 '18 at 18:40
1

I can only duplicate this if I execute such a script:

$ echo $path
/usr/local/bin /usr/bin /usr/local/sbin /usr/sbin

$ ./script.csh
setting path
$ echo $path
/usr/local/bin /usr/bin /usr/local/sbin /usr/sbin

If you instead source the script, you'll see different behavior:

$ source script.csh
setting path
$ echo $path
/usr/local/bin /usr/bin /usr/local/sbin /usr/sbin /sbin:/mscc/apps

(Perhaps you want /sbin /mscc/apps with a space instead of a colon separating the elements?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.