UNIX Tutorial Eight

8.1 UNIX Variables

Variables are a way of passing information from the shell to programs when you run them. Programs look "in the environment" for particular variables and if they are found will use the values stored. Some are set by the system, others by you, yet others by the shell, or any program that loads another program.

Standard UNIX variables are split into two categories, environment variables and shell variables. In broad terms, shell variables apply only to the current instance of the shell and are used to set short-term working conditions; environment variables have a farther reaching significance, and those set at login are valid for the duration of the session. By convention, environment variables have UPPER CASE and shell variables have lower case names.

8.2 Environment Variables

An example of an environment variable is the OSTYPE variable. The value of this is the current operating system you are using. Type

$ echo $OSTYPE

More examples of environment variables are

Finding out the current values of these variables.

ENVIRONMENT variables are set using the export command, displayed using the printenv or env commands, and unset using the export -n command.

To show all values of these variables, type

$ printenv | less

M.Stonebank@surrey.ac.uk October 2001