article

Environment variables are a set of dynamic values that can affect the way running processes will behave on a computer.

Synopsis


In all Unix and Unix-like systems, each process has its own private set of environment variables. By default, when a process is created it inherits a duplicate environment of its parent process, except for explicit changes made by the parent when it creates the child. All Unix operating system flavors as well as DOS and Microsoft Windows have environment variables; however, they do not all use the same variable names. Running programs can access the values of environment variables for configuration purposes. Examples of environment variables include
  1. The PATH which lists directories the shell searches for commands the user may type.
  2. HOME (Unix-like) and userprofile (Microsoft Windows) indicate where a user's home directory is located in the file system.
  3. TERM (Unix-like) specifies the type of computer terminal or terminal emulator being used (e.g., vt100 or dumb).
  4. CVS_RSH (Unix-like) is used to tell CVS which rsh-like program to use.
  5. MAIL (Unix-like) is used to indicate where a user's mail is to be found.

Shell scripts and batch files use environment variables to store temporary values for reference later in the script, and also to communicate data and preferences to child processes.

An environment variable that is changed in a script or compiled program will only affect that process and possibly child processes. The parent process and any unrelated processes will not be affected.

In Unix, the environment variables are normally initialized during system startup by the system init scripts, and thence inherited by all other processes in the system. Users can, and often do, augment them in the profile script for the shell they are using. In Microsoft Windows, environment variables defaults are stored in the windows registry.

The variables can be used both in scripts and on the command line. They are usually referenced by putting special symbols in front of or around the variable name. For instance, to display the program search path on a DOS or Windows system, the user could type in this command:

echo %PATH%

In the bash shell for Unix (also available for Windows), either of the two commands below could be used:

echo $PATH echo ${PATH}

Other scripting and shell environments sometimes use other symbols for the same purpose.

To set a variable to a particular value in DOS-WINDOWS, use: SET VARIABLE=value

The Unix equivalent is: VARIABLE=value (Except in csh, where the command used to modify the environment is setenv.)

In Unix shells such as sh and csh, the env command displays all environment variables along with their values.

Common environment variables


Unix

Note that, on a Unix system, a lot of environment variables normally exist, many of them very significant for programs to be working normally. This list is only a very brief list of some of the more significant ones (some would probably argue that there are others which are more significant). Please see your Unix system manual for further information.

$PATH
Contains a colon-separated list of directories that the shell searches for commands that do not contain a slash in their name. (Commands with slashes are interpreted as a file name to execute, and the shell attempts to execute them as they are)

$HOME
Contains the location of the user's home directory. Although the current user's home directory can also be found out through the C functions getpwuid and getuid, $HOME is often used for convenience in various shell scripts (and other contexts).

$DISPLAY
Contains the identifier for the display that X11 programs should use by default.

$LD_LIBRARY_PATH
On many Unix systems with a dynamic linker, contains a colon-separated list of directories that the dynamic linker should search for shared objects when building a process image after exec.

Microsoft Windows

%AppData%
Contains the full path to the Application Data folder of the user logged in. does NOT work on Windows NT 4.0 SP6 UK

%ComSpec%
This variable cotains the full path to the Windows NT command processor, cmd.exe.

%PATH%
This variable contains a semicolon-delimited list of directories in which the command interpreter will search for executable files. Equivalent to the UNIX $PATH variable.

%ProgramFiles%
This variable points to Program Files directory, which stores all the installed program of Windows and others. The default is C:\Program Files.

%SystemDrive%
The %SystemDrive% variable is a special system-wide environment variable found on Microsoft Windows NT and its derivatives. Its value is the drive upon which the system folder was placed.

The value of %SystemDrive% is in most cases C:. The system drive cannot be altered once the operating system is running.

%SystemRoot%
The %SystemRoot% variable is a special system-wide environment variable found on Microsoft Windows NT and its derivatives. Its value is the location of the system folder, including the drive and path.

The drive is the same as %SystemDrive% and the default path on a clean installation depends upon the version of the operating system. By default on a clean installation,

  • Windows NT 5.1 (Windows XP) and newer versions by default use \WINDOWS
  • Windows NT 5.0 (Windows 2000), Windows NT 4.0 and Windows NT 3.1 by default use \WINNT
  • Windows NT 3.5x by default uses \WINNT35

%UserProfile%
The %UserProfile% variable is a special system-wide environment variable found on Microsoft Windows NT and its derivatives. Its value is the location of the current user's profile directory, in which is found that user's HKCU registry hive (NTUSER).

You can also use the %USERNAME% variable to determine the active users login identification.

%WinDir%
This variable points to the Windows directory. If the System is on drive c: then the default values are:
  • C:\WINDOWS on Windows XP and Windows 95, Windows 98 and Windows ME
  • C:\WINNT for Windows NT 4 and Windows 2000

External links


Unix shells | Operating system technology

Umgebungsvariable | Ympäristömuuttuja | Environnement d'exécution | Variabile d'ambiente | 環境変数

 

This article is licensed under the GNU Free Documentation License. It uses material from the "Environment variable".

Home Pageartsbusinesscomputersgameshealthhospitalshomekids & teensnewsphysiciansrecreationreferenceregionalscienceshoppingsocietysportsworld