A shell maintains an environment that includes a set of variables defined by the login program, the system initialization file, and the user initialization files. In addition, some variables are defined by default. A shell can have two types of variables:
Environment variables - Variables that are exported to all processes spawned by the shell. Their settings can be seen with the env command. A subset of environment variables, like PATH, affects the behavior of the shell itself.
Shell (local) variables - Variables that affect only the current shell. In the C shell, a set of these shell variables have a special relationship to a corresponding set of environment variables. These shell variables are user, term, home, and path. The value of the environment variable counterpart is initially used to set the shell variable.
In the C shell, you use the lowercase names with the set command to set shell variables and use uppercase names with the setenv command to set environment variables. If you set a shell variable, the shell sets the corresponding environment variable and vice versa. For example, if you update the path shell variable with a new path, the shell also updates the PATH environment variable with the new path.
In the Bourne and Korn shells, you use the uppercase names with the setenv command to set both shell and environment variables. You also have to use the export command to finish setting environment variables. For all shells, you generally refer to shell and environment variables by their uppercase names.
In a user initialization file, you can customize a user's shell environment by changing the values of the predefined variables or by specifying additional variables. The table below shows how to set environment variables in a user initialization file.
Table 2-14 Setting Environment Variables in a User Initialization File
If You Want to Set a User's Environment Variables for The ... |
Then Add the Following Line to the User Initialization File ... |
---|---|
setenv MAIL /var/mail/ripley |
|
VARIABLE=value; export VARIABLE Example: MAIL=/var/mail/ripley;export MAIL |
The table below describes environment and shell variables you might want to customize in a user initialization file. For more information about variables used by the different shells, see sh(1), ksh(1), or csh(1).
Table 2-15 Shell and Environment Variable Descriptions