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.
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
ENVIRONMENT variables are set using the setenv command, displayed using the printenv or env commands, and unset using the unsetenv command.
To show all values of these variables, type
% printenv | less
The names of the standard shell variables are different for different shells. An example of a shell variable used by bash is HISTSIZE, which is the number of lines of command history to retain. The variable used for this purpose by tcsh is history. (tcsh follows the convention that shell variables have lowercase names, while environment variables have uppercase names. bash conventionally uses uppercase for both.)
SHELL variables are both set and displayed using the set command. They can be unset by using the unset command.
To show all values of these variables, type
% set | less
Each time you login to a UNIX host, or start a shell from within an existing session, the system initializes environment and shell variables for you using various hidden files (files whose names begin with .). The names of these files depend on the shell being used - see the appropriate man pages.
M.Stonebank@surrey.ac.uk October 2001
Modified for use at Gordon College - russell.bjork@gordon.edu, July 18, 2010.