Environment Variables

Another common function of the shell is environment variables. An environment variable is a name/value pair that can be read by any program invoked by the shell. Here is a list of common environment variables and what they mean:

Variable

Description

USER

The login name of the current user.

PATH

A colon-separated list of directories in which the shell looks for commands. If a program is in a directory that is not in the user’s path, the path to the file must be given for the shell to find it.

SHELL

The name of the shell you are using.

EDITOR

The user's preferred text editor. Programs that need to let you edit text will usually use your preferred editor to do so. The default editor on your virtual server is pico, but you can change it to whatever editor you wish.

PAGER

The user's preferred text pager. Programs that display a lot of text will often use your preferred pager program to make it easier to read. The default text pager is more.

The method for viewing or setting an environment variable differs somewhat from shell to shell. For example, in the C-Style shells such as tcsh and csh, you would use the “setenv” command to set and view environment variables. Under Bourne shells such as sh and bash, you would use the “set” and “export” commands instead. For example, to set or modify the EDITOR environment variable, in a csh or tcsh shell, a command like this would set EDITOR to /usr/local/bin/vi:

> setenv EDITOR /usr/local/bin/vi

Under Bourne shells:

> export EDITOR="/usr/local/bin/vi"

You can also make most shells expand the environment variable by placing a $ character in front of it on the command line. For example, echo $USER would print out your user name because the shell expands $USER and passes it on to the echo command, which prints it on the screen.