This page was moved from the Toolserver wiki.
Toolserver has been replaced by Toolforge. As such, the instructions here may no longer work, but may still be of historical interest.
Please help by updating examples, links, template links, etc. If a page is still relevant, move it to a normal title and leave a redirect.
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
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_ADDRESSfirstname.lastname@example.org 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:
- 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.
- The operating system sets some variables upon login, such as
- The user can set or change environment variables in his shell init file (e.g.
Changing the environment
The easiest way to set or change environment variables is to set them in your
$HOME/.environment file, which just contains a list of NAME=value pairs, one per line; for example:
Blank lines and lines starting with a '#' character will be ignored.