8

Possible Duplicate:
Different ways to execute a shell script

What happens when I issue the following command:

source devenv.csh

How does it differ from running it just as devenv.csh ?

Geek
  • 6,688

1 Answers1

14

When you "just run" the file, the interpreter given in the shebang (the first line of the script, starting with #!, e.g. #!/usr/bin/csh) is executed with devenv (or devenv.csh, this is a bit inconsistent in the question) as a parameter. It will then execute the commands in the file and terminate.

Sourceing the file means the commands are executed in the current shell. When some of the commands in devenv.csh change the environment (and the file name hints that this is the main purpose of this particular file), executing it will have no effect: the environment will be changed in the subshell, but that will terminate right away, leaving no trace of the changed settings. Note that environment variables never propagate "upward": they can only be inherited by subprocesses, but not by parents.

  • And that's why many Gentoo "what if I want the new settings now?" solutions are source /etc/profile, not bash /etc/profile, and why you use source inside .bashrc and .bash_profile if you want to build on additional files. – njsg Feb 05 '13 at 10:46