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, those that are exported (available to programs you run) and those that are not. In broad terms, unexported variables apply only to the current instance of the shell and are used to set short-term working conditions; exported ones have a farther reaching significance, and those set at login are valid for the duration of the session. By convention, exported variables have UPPER CASE and unexported variables have lower case names.
Note: Nomenclature differs between shells. This page documents bash. If you are using the C shell (try not to), the examples here will not work.
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 variable=value, displayed using the env command, and unset using the unset command.
To show all values of these variables, type
% env | less
Examples of environment variables that you will find already exist are
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, the system looks in your home directory for initialisation files. Information in these files is used to set up your working environment. The bash shell uses two files called .bashrc and .bash_profile (note that both file names begin with a dot).
When you log in, these files are read and any variables set in them become part of your environment.
WARNING: NEVER put commands that run graphical displays (e.g. a web browser) or other programs that do not quickly run to completion in these files.
When you type a command, your path (or PATH) variable defines in which directories the shell will look to find the command you typed. If the system returns a message saying "command: Command not found", this indicates that either the command doesn't exist at all on the system or it is simply not in your path.
For example, to run units, you either need to directly specify the units path (~/units174/bin/units), or you need to have the directory ~/units174/bin in your path.
You can add it to the end of your existing path (the $PATH represents this) by issuing the command:
% PATH=$PATH:~/units174/bin
Test that this worked by trying to run units in any directory other that where units is actually located.
% cd; units
HINT: You can run multiple commands on one line by separating them with a semicolon.
To add this path PERMANENTLY, add the following line to your .cshrc AFTER the list of other commands.
PATH=$PATH:~/units174/bin
Note that . (the current directory) may or may not be in your path. In other words, being the same directory as program doesn't always mean that you can run it with just its name. But you can run it by saying, e.g.
./units