Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

marked as duplicate by manatwork, jofel, Renan, uther, rahmu Feb 5 '13 at 13:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 3 down vote accepted

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.

share|improve this answer
    
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 5 '13 at 10:46
add comment

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