CSH Script - Difference between Set and Setenv

Hi,
I am wondering if some one could elaborate the difference between ‘Set’ and ‘Setenv’. As can be noticed the CMAQ scripts contains both.

Thanks
MMS

Think of shell-variables (e.g., using set foo=bar) as being local variables of the shell that you are running, itself; they don’t exist for programs or other scripts that the shell launches, etc.
On the other hand, environment-variables (e.g., using setenv qux whatever) do exist in such programs or other scripts launched by that shell. So, in the example:

    set foo = bar
    setenv qux /my/file.nc
   time myprogram.exe
   runqa.csh

In this example, myprogram.exe and runqa.csh can “see” qux and its value, but they cannot see foo.

The “local-variable” nature of the shell variables is particularly useful when you have one shell-script invoking another:

Let script1.csh be:

    #/bin/tcsh
    set foo = bar
    echo "In script1:  foo= ${foo}"
    script2.csh
    echo "In script1:  foo= ${foo}"

and script2.csh be:

    #/bin/tcsh
    set foo = qux
    echo "In script2:  foo= ${foo}"

This will generate the output

In script1:  foo=bar
In script2:  foo=qux
In script1:  foo=bar

Note that last line: setting foo in script2 only affected script2; it did not affect foo in script1.

Of course, there are lots of people that don’t really understand this, and who use set and setenv indiscriminately :slight_smile: