Toolserver:Environment

From mediawiki.org

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 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[edit]

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:

LANG=fr_FR.UTF-8
EDITOR=vim

Blank lines and lines starting with a '#' character will be ignored.

Environment variables set this way will take effect for interactive login sessions, cron jobs, and SGE jobs. However, currently they will not affect (Fast)CGI scripts on the web server.

Category:Documentation