35.5. Predefined Environment Variables
We've said that
environment variables are used to store information that
you'd rather not worry about, and that there are a
number of standard environment variables that many Unix programs use.
These are often called "predefined"
environment variables -- not because their values are predefined,
but because their names and uses are predefined. Here are some
important ones:
- PATH (Section 35.6)
-
contains your command search path
(Section 27.6). This is a list of directories in which the
shell looks to find commands.
It's usually set in
one of your shell setup files (Section 3.3).
- EDITOR and VISUAL
-
can be loaded with the name of your favorite editor.
They're usually set in one of your shell setup
files. Some programs distinguish between EDITOR
(usually set to a line editor (Section 20.1) such as ed) and
VISUAL (set to a full-screen editor like
vi). Many people don't follow
that convention; they set both to the same editor. (The Korn shell
checks VISUAL and EDITOR,
in that order, to determine your command
editing mode (Section 30.14).)
- PRINTER (Section 45.4) or LPDEST
-
can be loaded with the name of your default printer. This is quite
useful at a site with many printers -- you don't
need to tell lpr or lp (Section 45.2) which printer to use.
(PRINTER works on systems that print with
lpr , and LPDEST is
for lp.) This variable is usually set in one of
your shell setup files.
- PWD
-
may contain the absolute pathname of your current directory.
It's set automatically by the cd command in some Unix shells. PWD may be
fooled by cding through symbolic links.
- HOME (Section 31.11) (called LOGDIR on some systems)
-
contains the absolute pathname of your home directory.
It's set automatically when you log in.
- SHELL
-
contains the absolute pathname of your login shell.
It's set automatically whenever you log in.
- USER or LOGNAME
-
contains your username. It's set automatically when
you log in.
- TERM
-
contains the name of your terminal type in the
termcap or terminfo
database. It's usually set in a shell setup file. On
Darwin, in the Terminal program, the
TERM_PROGRAM variable is also set.
- TERMCAP
-
is an environment variable that can be loaded with the complete
termcap database entry for the terminal you are
using. This may make some programs start up more quickly, but
it's not necessary. It's set (under
some conditions) by the tset command, which is
usually run in your shell setup file.
- ENV
-
contains the name of an initialization file to be executed whenever a
new Korn shell is started. (See Section 3.3.) Korn shell only.
- BASH_ENV
-
contains the name of an initialization file to be executed whenever a
new bash shell is started. (See Section 3.3.) bash only. Often set to
.bashrc by default.
- PAGER
-
can be set to the name of your favorite page-by-page screen display
program like less (Section 12.3) or
more. (Programs like man (Section 2.1) use
PAGER to determine which paging program to use
if their output is longer than a single screen.)
- PS1
-
contains the primary prompt (i.e., interactive command prompt) for
Bourne-type shells. You also can set it in a particular shell, as a
shell variable with the same name, but it won't be
passed to subshells automatically. (The C shell
doesn't store the prompt in an environment variable.
It uses a shell variable called prompt because
the .cshrc file (Section 3.3) is read to set up each instance of the shell.
See Section 4.4.)
- PS2 (Section 28.12)
-
contains the secondary prompt (used within compound commands like
while and for) for Bourne
shells. Some Bourne-type shells also use PS3 and
PS4. As with PS1, these
don't have to be stored in the environment.
- MANPATH (Section 3.21)
-
if your man (Section 2.1) command supports it, is a colon-separated
list of directories to search for manual pages.
- TZ
-
contains the time zone. This is the name of a file in the
zoneinfo directory that provides time zone
information for your locality. It is read by commands such as
date.
- DISPLAY
-
is used by the X Window System
(Section 1.22) to identify the display server
(keyboard and screen handling program) that will be used for input
and output by X applications. It may be set by ssh
when you log into a remote system, as well.
- INPUTRC
-
lets you choose a setup filename for the Readline library instead of
the default $HOME/.inputrc.
- LS_COLORS (or LS_COLOURS)
-
lists the colors used by the color ls
command (Section 8.6).
Because Bourne-type shells
don't make as strict a distinction between
environment variables and shell variables as the C shell does,
we've included a few things here that might not be
on other people's lists.
But we haven't even tried to include everything.
Here are two good ways to see what's there. One is
to look at the end of a command's manual page (Section 2.1) in
the ENVIRONMENT section (if there is one). Another is to list your
current environment variables (with env or
printenv (Section 35.3)) and make some
guesses from the names and corresponding values.
We may have implied that environment variables are relatively
constant (like your favorite editor). That's not
true. For example, in a windowing environment, the current length of
your window might be kept in an environment variable. That can change
as often as you resize your window. What is true (fortunately) is
exactly what we've said: environment variables store
information that you'd rather not have to worry
about.
--ML, JP, and SJC
| | |
35.4. Parent-Child Relationships | | 35.6. The PATH Environment Variable |
Copyright © 2003 O'Reilly & Associates. All rights reserved.