Skip to main content

Environment Variables

By default, a variable is local to the shell in which it is running.

You can export variables to make them environment variables. That means that they are passed to programs executed by the shell.

Environment variables are used by all proccesses, not just the shell, and are commonly used to pass configuration information to programs.

To create an environment variable named X with a value of 999:

$ X=999
$ export X

Or in a single step:

$ export X=999

You can view all of the current variables (and shell functions) with the set command, or just the environment variables with the printenv command (you'll probably want to pipe the output through less).

The term environment variable is often shortened to the abbreviation envar.

Common Environment Variables

Environment VariablePurposeExamples
PS1Normal (first-level) shell promptPS1="Enter command: "
PS1="[\u@\h \W]$ "
EDITORPath to the default text editor (typically /usr/bin/nano)EDITOR=/usr/bin/vi
PATHA colon-separated list of directories that will be searched when looking for a commandPATH="$PATH:."
PATH="/usr/bin:/usr/sbin:."
LANGThe default language -- used to select message translations as well as number, currency, date, and calendar formats.LANG=en_CA.UTF-8
LANG=fr_CA.UTF-8
HOMEThe user's home directory - used for relative-to-home pathnames.HOME=/var/tmp
RANDOMA random integer (0-32767)