Common environment variables

Any program can make use of environment variables (check its man page or documentation to determine what variables it supports). However, there are some environment variables that are understood by many programs. They include:

EDITOR

specifies the editor that will be used by other programs, such as a mail program.

PAGER

specifies the pager that will be used by programs, such as man, to display long files ``one page at a time.'' Common pagers are more and less.

PATH

specifies the directories that the shell will look in to find commands. The directories listed in the PATH are searched in the order in which they appear.

PRINTER

specifies the default printer to which the lpr command (the default printing command) will send output.

TERM

specifies the terminal (display) you are using. Common values are xterm, vt100, rxvt, and linux. Only occasionally will users find it necessary to set this by hand.

In bash, you can use the echo command to display the current settings of these variables, and the export command to set new values.

Example 4-2. Exporting variables in the shell


$ echo $EDITOR
nano
$ export EDITOR=vim
$ echo $PAGER

$ PAGER=less
$ export PAGER

These settings would change the default editor from nano to vim, and define less as a default pager. Notice that the export command can be separate or combined with a variable assignment on one line.