Environment variable

From Free net encyclopedia

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

Contents

Background

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.

In Unix, 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 Windows, environment variables are stored globally in the windows registry, and changes are seen by all processes that see the relevant registry changes.

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 show all the variables that are set in a prompt (DOS-WINDOWS) use:

SET

The Unix equivalent is:

env

Microsoft Windows

%AppData%

Contains the full path to the Application Data folder of the user logged in.

%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 path depends upon the version and circumstances of the operating system. By default,

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

The %SystemRoot% may be different if the system was upgraded from earlier version of Windows NT, or from Windows 3.1, Windows 95, Windows 98, or Windows Me.

%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).

%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

Other environment variables

External links

fi:Ympäristömuuttuja fr:Environnement d'exécution it:Variabile d'ambiente ja:環境変数