In C and C++ these values can be queried with the library function getenv(3). Perl and Python initialize environment-dictionary objects at startup. Other languages generally follow one of these two models.
Login name of the account under which this session is logged in (BSD convention).
Login name of the account under which this session is logged in (System V convention).
The number of character-cell columns on the controlling terminal or terminal-emulator window.
The number of character-cell rows on the controlling terminal or terminal-emulator window.
The name of the user's command shell (often used by shellout commands).
Name of the terminal type of the session console or terminal emulator window (see the terminfo case study in Chapter 6 for background). TERM is special in that programs to create remote sessions over the network (such as telnet and ssh) are expected to pass it through and set it in the remote session.
(This list is representative, but not exhaustive.)
The HOME variable is especially important, because many programs use it to find the calling user's dotfiles (others call some functions in the C runtime library to get the calling user's home directory).
Note that some or all of these system environment variables may not be set when a program is started by some other method than a shell spawn. In particular, daemon listeners on a TCP/IP socket often don't have these variables set — and if they do, the values are unlikely to be useful.
There are, however, some design patterns in which user-defined environment variables can be useful:
Application-independent preferences that need to be shared by a large number of different programs. This set of ‘standard’ preferences changes only slowly, because lots of different programs need to recognize each one before it becomes useful.[102] Here are the standard ones:
The name of the user's preferred editor (often used by shellout commands).[103]
The name of the user's preferred mail user agent (often used by shellout commands).
The name of the user's preferred program for browsing plaintext.
The name of the user's preferred program for browsing Web URLs. This one, as of 2003, is still very new and not yet widely implemented.
Environment variables have only very limited portability off Unix. Microsoft operating systems have an environment-variable feature modeled on that of Unix, and use a PATH variable as Unix does to set the binary search path, but most of other variables that Unix shell programmers take for granted (such as process ID or current working directory) are not supported. Other operating systems (including classic MacOS) generally do not have any local equivalent of environment variables.
[102] Nobody knows a really graceful way to represent this sort of distributed preference data; environment variables probably are not it, but all the known alternatives have equally nasty problems.
[103] Actually, most Unix programs first check VISUAL, and only if that's not set will they consult EDITOR. That's a relic from the days when people had different preferences for line-oriented editors and visual editors.