Shell and environment variables

Shell and environment variables both associate string (not numeric) values with identifiers; the difference is that shell variables are local to that shell, while enviroment variables are accessible to and inherited by any children run by that shell.

To create a shell variable, simply say variable=value; note that there must not be spaces around the = and if the value needs to contain spaces or other shell special characters, it needs to be quoted.

Environment variables are created by creating a shell variable and using export variable to place it in the environment; it is also conventional to name environment variables with ALL CAPS.

Either kind of variable can be referred to with $variable or ${variable} (which ensures that the variable name won't merge with text around it).

Some environment variables have special meaning for the execution environment, such as PATH which specifies a :-separated list of directories to search for executables.

Here are some commonly-encountered special variables used by the shell:


Steve VanDevender
Last modified: Thu Jul 1 14:16:21 PDT 2004