[Next] [Previous] [Up] [Top] [Contents]
CHAPTER 5 Shells
5.2 Environment Variables
Environmental variables are used to provide information to the programs you use. You can have both global environment and local shell variables. Global environment variables are set by your login shell and new programs and shells inherit the environment of their parent shell. Local shell variables are used only by that shell and are not passed on to other processes. A child process cannot pass a variable back to its parent process.
The current environment variables are displayed with the "env" or "printenv" commands. Some common ones are:
- DISPLAY The graphical display to use, e.g. nyssa:0.0
- EDITOR The path to your default editor, e.g. /usr/bin/vi
- GROUP Your login group, e.g. staff
- HOME Path to your home directory, e.g. /home/frank
- HOST The hostname of your system, e.g. nyssa
- IFS Internal field separators, usually any white space (defaults to tab, space and <newline>)
- LOGNAME The name you login with, e.g. frank
- PATH Paths to be searched for commands, e.g. /usr/bin:/usr/ucb:/usr/local/bin
- PS1 The primary prompt string, Bourne shell only (defaults to $)
- PS2 The secondary prompt string, Bourne shell only (defaults to >)
- SHELL The login shell you're using, e.g. /usr/bin/csh
- TERM Your terminal type, e.g. xterm
- USER Your username, e.g. frank
Many environment variables will be set automatically when you login. You can modify them or define others with entries in your startup files or at anytime within the shell. Some variables you might want to change are PATH and DISPLAY. The PATH variable specifies the directories to be automatically searched for the command you specify. Examples of this are in the shell startup scripts below.
You set a global environment variable with a command similar to the following for the C shell:
% setenv NAME value
and for Bourne shell:
$ NAME=value; export NAME
You can list your global environmental variables with the env or printenv commands. You unset them with the unsetenv (C shell) or unset (Bourne shell) commands.
To set a local shell variable use the set command with the syntax below for C shell. Without options set displays all the local variables.
% set name=value
For the Bourne shell set the variable with the syntax:
$ name=value
The current value of the variable is accessed via the "$name", or "${name}", notation.
Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]