Toolserver:Environment

The Unix environment is a list of key/value pairs (variables) associated with a Unix process. Each process inherits the environment from its parent, and can modify it; any modifications will be passed on to its children. A process cannot change another process's environment.

Environment variables serve two purposes; firstly, they provide a way for a user to configure the behaviour of the system, for example by setting his preferred text editor. Secondly, they provide information about the system or user for use in shell scripts.

Environment variables are not the same as shell variables. Shell variables can be turned into environment variables using the export command.

By convention, environment variables are written in uppercase. Some typical variables might be:

HOME=/home/jsmith                   # the user's home directory EDITOR=vim                          # the user's preferred text editor LOGNAME=jsmith                      # Username, for use in shell scripts etc. SHELL=/bin/bash                      # the user's login shell PATH=/bin:/usr/sbin:/usr/local/bin  # the search path for commands entered at the shell prompt

To show the current value of a variable: % echo $HOME /home/jsmith

To show all environment variables: % env _=/bin/env EMAIL_ADDRESS=river@loreley.flyingparchment.org.uk REAL_NAME=River Tarnell MANPATH=/opt/ts/share/man:/opt/SUNWspro/man:/usr/share/man:/usr/sfw/share/man DMAKE_MODE=parallel [etc]

There are three general sources for environment variables:
 * 1) Your SSH client sets some variables, such as $LANG (which sets the system character set, e.g. UTF-8, and the interface language), and $TERM, which tells the OS what kind of terminal emulator the user has.
 * 2) The operating system sets some variables upon login, such as $PATH and $LOGNAME.
 * 3) The user can set or change environment variables in his shell init file (e.g. .bash_profile).

Changing the environment
The most common way to set environment variables is in your shell profile; this is a special script which is executed when you log in. Setting them here ensures they're always set automatically when you log in.

If you use bash, the default shell, your shell init file is $HOME/.bash_profile. If you use a different shell, you should probably know its init file location.

To set variables in the init file, simply edit the file, and add commands such as:

EDITOR=joe PATH=$PATH:$HOME/bin export EDITOR PATH

The export line is important; this ensures the variables are visible to all processes, not just the shell.

To change a variable for the current login session only, you can use the same syntax; simply type it on the shell command line.

If you use a csh-style shell (not bash), the syntax is different. csh users should probably know the syntax; if not, see csh(1).