Environment variable
Encyclopedia
Environment variables are a set of dynamic named value
Value (computer science)
In computer science, a value is an expression which cannot be evaluated any further . The members of a type are the values of that type. For example, the expression "1 + 2" is not a value as it can be reduced to the expression "3"...

s that can affect the way running processes will behave on a computer.

They can be said in some sense to create the operating environment
Operating environment
The operating environment in engineering describes the circumstances surrounding and potentially affecting something that is operating. For example electronic or mechanical equipment may be affected by high temperatures, vibration, dust, and other parameters which comprise the operating...

 in which a process runs. For example, an environment variable with a standard name can store the location that a particular computer system uses to store temporary file
Temporary file
Temporary files may be created by computer programs for a variety of purposes; principally when a program cannot allocate enough memory for its tasks, when the program is working on data bigger than the architecture's address space, or as a primitive form of inter-process communication.- Auxiliary...

s—this may vary from one computer system to another. A process which invokes the environment variable by (standard) name can be sure that it is storing temporary information in a directory that exists and is expected to have sufficient space.

Synopsis

In all Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 and Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 systems, each process has its own private set of environment variable
Variable (programming)
In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...

s. 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. At API level, these changes must be done between fork and exec. Alternatively, from shells such as bash, you can change environment variables for a particular command invocation by indirectly invoking it via env
Env
env is a shell command for Unix and Unix-like operating systems. It is used to either print a list of environment variables or run another utility in an altered environment without having to modify the currently existing environment. Using env, variables may be added or removed, and the values of...

or using the ENVIRONMENT_VARIABLE=VALUE <command> notation. All Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

 flavors, MS-DOS
MS-DOS
MS-DOS is an operating system for x86-based personal computers. It was the most commonly used member of the DOS family of operating systems, and was the main operating system for IBM PC compatible personal computers during the 1980s to the mid 1990s, until it was gradually superseded by operating...

, and Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 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:
  • PATH
    Path (variable)
    PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located...

     - lists directories the shell
    Shell (computing)
    A shell is a piece of software that provides an interface for users of an operating system which provides access to the services of a kernel. However, the term is also applied very loosely to applications and may include any software that is "built around" a particular component, such as web...

     searches, for the commands the user
    User (computing)
    A user is an agent, either a human agent or software agent, who uses a computer or network service. A user often has a user account and is identified by a username , screen name , nickname , or handle, which is derived from the identical Citizen's Band radio term.Users are...

     may type without having to provide the full path.
  • HOME (Unix-like
    Unix-like
    A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

    ) and USERPROFILE (Microsoft Windows) - indicate where a user's home directory
    Home directory
    A Home directory is a file system directory on a multi-user operating system containing files for a given user of the system. The specifics of the home directory is defined by the operating system involved; for example, Windows systems between 2000 and 2003 keep home directories in a folder...

     is located in the file system
    File system
    A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...

    .
  • HOME/{.AppName} (Unix-like
    Unix-like
    A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

    ) and APPDATA\{DeveloperName\AppName} (Microsoft Windows) - for storing application settings. Many open source programs incorrectly use USERPROFILE for application settings in Windows - USERPROFILE should only be used in dialogs that allow user to choose between paths like Documents/Pictures/Downloads/Music, for programmatic purposes APPDATA (roaming), LOCALAPPDATA or PROGRAMDATA (shared between users) is used.
  • TERM (Unix-like
    Unix-like
    A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

    ) - specifies the type of computer terminal
    Computer terminal
    A computer terminal is an electronic or electromechanical hardware device that is used for entering data into, and displaying data from, a computer or a computing system...

     or terminal emulator
    Terminal emulator
    A terminal emulator, terminal application, term, or tty for short, is a program that emulates a video terminal within some other display architecture....

     being used (e.g., vt100
    VT100
    The VT100 is a video terminal that was made by Digital Equipment Corporation . Its detailed attributes became the de facto standard for terminal emulators.-History:...

    or dumb).
  • PS1 (Unix-like
    Unix-like
    A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

    ) - specifies how the prompt is displayed in the Bourne shell
    Bourne shell
    The Bourne shell, or sh, was the default Unix shell of Unix Version 7 and most Unix-like systems continue to have /bin/sh - which will be the Bourne shell, or a symbolic link or hard link to a compatible shell - even when more modern shells are used by most users.Developed by Stephen Bourne at AT&T...

     and variants.
  • MAIL (Unix-like
    Unix-like
    A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

    ) - used to indicate where a user's mail is to be found.
  • TEMP - location where processes can store temporary files


Shell script
Shell script
A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language...

s and batch files use environment variables to communicate data and preferences to child processes. They can also be used to store temporary values for reference later in the script, although in Unix other variables are usually used for this.

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 MS-DOS, changing or removing a variable's value inside a BATCH file will change the variable for the duration of command.com's existence.

In Unix, the environment variables are normally initialized during system startup by the system init scripts, and hence 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
Windows registry
The Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems. It contains settings for low-level operating system components as well as the applications running on the platform: the kernel, device drivers, services, SAM, user...

 or set in autoexec.bat.

Getting and setting environment variables

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, in most scripting environments, the user has to type:


echo $PATH


On DOS or Windows systems, the user has to type this:


echo %PATH%

Unix

The commands env, set, and printenv display all environment variables and their values. env and set are also used to set environment variables and are often incorporated directly into the shell. printenv can also be used to print a single variable by giving that variable name as the sole argument to the command.

In Unix, the following commands can also be used, but are often dependent on a certain shell.
export VARIABLE=value # for Bourne
Bourne shell
The Bourne shell, or sh, was the default Unix shell of Unix Version 7 and most Unix-like systems continue to have /bin/sh - which will be the Bourne shell, or a symbolic link or hard link to a compatible shell - even when more modern shells are used by most users.Developed by Stephen Bourne at AT&T...

, bash, and related shells
setenv VARIABLE value # for csh
C shell
The C shell is a Unix shell that was created by Bill Joy while a graduate student at University of California, Berkeley in the late 1970s. It has been distributed widely, beginning with the 2BSD release of the BSD Unix system that Joy began distributing in 1978...

 and related shells

Working principles of environment variables

A few simple principles govern how environment variables BY INSTALLING, achieve their effect.
Local to process

Environment variables are local to the process in which they were set. That means if we open two terminal windows (Two different processes running shell) and change value of environment variable in one window, that change will not be seen by other window.
Inheritance

When a child process is created, it inherits all the environment variables and their values from the parent process. Usually, when a program calls another program, it first creates a child process by forking, then the child adjusts the environment as needed and lastly the child replaces itself with the program to be called. This procedure gives the calling program control over the environment of the called program.
Case sensitive

In Unix and Unix-like systems the names of environment variables are case sensitive.

DOS and Windows

In DOS and Windows, the set command without any arguments displays all environment variables along with their values.

To set a variable to a particular value, use:


set VARIABLE=value


However, this is temporary. Permanent change to the environment variable can be achieved through editing the registry (not recommended for novices) and using the Windows Resource Kit
Resource Kit
Resource Kit is a term used by Microsoft for a set of software resources and documentation released for their software products, but which is not part of that product...

 application setx.exe. With the introduction of Windows Vista
Windows Vista
Windows Vista is an operating system released in several variations developed by Microsoft for use on personal computers, including home and business desktops, laptops, tablet PCs, and media center PCs...

, the setx command became part of Windows.

Users of the Windows GUI can manipulate variables via ; through the Windows Registry
Windows registry
The Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems. It contains settings for low-level operating system components as well as the applications running on the platform: the kernel, device drivers, services, SAM, user...

 this is done changing the values under HKCU\Environment (for user specific variables) and HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment (for System variables).

To set a variable whose name is in another variable, you can do:


set %VARNAME%=value


This feature allows certain interesting applications. For example, you may create a uni-dimensional array of elements (vector) this way:


set VECTOR[%I%]=value of element subscript %I%
MkVec

set VECNAME=%1
set i=0
loop

shift
if "%1" "" goto exitloop
set /a i+=1
set %VECNAME%[%i%]=%1
goto loop
exitloop

exit /B %i%

call :MkVec DOWNAME=Monday Tuesday Wednesday Thursday Friday Saturday Sunday


To see the current value of a particular variable, use:


echo %VARIABLE%


or


set VARIABLE


Note: Please take note that doing so will print out all variables beginning with 'VARIABLE'.
Another example is:


C:\> set p
Path=c:\.. ..
PATHEXT=.COM;.EXE;.BAT;
PROCESSOR_ARCHITECTURE=.. ..
PROCESSOR_IDENTIFIER=x8..
PROCESSOR_LEVEL=6..
PROCESSOR_REVISION=1706..
ProgramFiles=C:\Program.. .
PROMPT=$P$G


To see the value of an array element a double expansion is required: one for the subscript value and an additional expansion for the array element. This may be achieved via Delayed !VARIABLE! Expansion this way:

set DOW=value of Day of Week (1..7)
echo !DOWNAME[%DOW%]!


To delete a variable, the following command is used:

set VARIABLE=

Unexported variables

In Unix shells, variables may be assigned without the export keyword. Variables defined in this way are displayed by the set command, but are not true environment variables, as they are stored only by the shell and not recognized by the kernel. The printenv command will not display them, and child processes do not inherit them.

VARIABLE=value

However, if used in front of a program to run, the variables will be exported to the environment and thus appear as real environment variables to the program:
VARIABLE=value program_name [arguments]

The tool that gives closest parallel in Windows is the SETLOCAL/ENDLOCAL commands that prevent variables from being set globally.
Security
On Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

, a setuid
Setuid
setuid and setgid are Unix access rights flags that allow users to run an executable with the permissions of the executable's owner or group...

 program is given an environment chosen by its caller, but it runs with different authority from its caller. The dynamic linker
Dynamic linker
In computing, a dynamic linker is the part of an operating system that loads and links the shared libraries for an executable when it is executed. The specific operating system and executable format determine how the dynamic linker functions and how it is implemented...

 will usually load code from locations specified by the environment variables LD_LIBRARY_PATH and LD_PRELOAD and run it with the process's authority. If a setuid program did this, it would be insecure, because its caller could get it to run arbitrary code and hence misuse its authority. For this reason, libc unsets these environment variables at startup in a setuid process. setuid programs usually unset unknown environment variables and check others or set them to reasonable values.

Examples of Unix environment variables

$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 file names to execute, and the shell attempts to execute the files directly). Equivalent to the Windows %PATH% variable. See Path (computing)
Path (computing)
A path, the general form of a filename or of a directory name, specifies a unique location in a file system. A path points to a file system location by following the directory tree hierarchy expressed in a string of characters in which path components, separated by a delimiting character, represent...



$HOME
Contains the location of the user's home directory
Home directory
A Home directory is a file system directory on a multi-user operating system containing files for a given user of the system. The specifics of the home directory is defined by the operating system involved; for example, Windows systems between 2000 and 2003 keep home directories in a folder...

. 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). Using the environment variable also gives the user the possibility to point to another directory.

$PWD
This variable points to the current directory. Equivalent to the output of the command pwd when called without arguments.

$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
Dynamic linker
In computing, a dynamic linker is the part of an operating system that loads and links the shared libraries for an executable when it is executed. The specific operating system and executable format determine how the dynamic linker functions and how it is implemented...

, contains a colon-separated list of directories that the dynamic linker should search for shared objects when building a process image after exec, before searching in any other directories.

$LANG, $LC_ALL, $LC_...
LANG is used to set to the default locale
Locale
In computing, locale is a set of parameters that defines the user's language, country and any special variant preferences that the user wants to see in their user interface...

. For example, if the locale values are pt_BR, then the language is set to (Brazilian) Portuguese and Brazilian practice is used where relevant. Different aspects of localization are controlled by individual LC_-variables (LC_CTYPE, LC_COLLATE
Collation
Collation is the assembly of written information into a standard order. One common type of collation is called alphabetization, though collation is not limited to ordering letters of the alphabet...

, LC_DATE etc.). LC_ALL can be used to force the same locale for all aspects.

$TZ
Refers to Time zone
Time zone
A time zone is a region on Earth that has a uniform standard time for legal, commercial, and social purposes. In order for the same clock time to always correspond to the same portion of the day as the Earth rotates , different places on the Earth need to have different clock times...

. It can be in several formats, either specifying the timezone itself or referencing a file (in /usr/share/zoneinfo).

Examples of DOS environment variables

%COMSPEC%
ComSpec
ComSpec is one of the environment variables used in MS-DOS and Microsoft Windows, which normally points to the command line interpreter, which is by default command.com in MS-DOS or cmd.exe in Windows NT...


This variable contains the full path to the command processor, command.com
COMMAND.COM
COMMAND.COM is the filename of the default operating system shell for DOS operating systems and the default command line interpreter on Windows 95, Windows 98 and Windows Me...

.

%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 (although note that PATH on Windows additionally performs the same task as LD_LIBRARY_PATH on Unix-like systems).
Note that %PATH% can also be set like this PATH=c:\dos; where SET isn't required.

%TEMP% and %TMP%
These variables contain the path to the directory where temporary file
Temporary file
Temporary files may be created by computer programs for a variety of purposes; principally when a program cannot allocate enough memory for its tasks, when the program is working on data bigger than the architecture's address space, or as a primitive form of inter-process communication.- Auxiliary...

s should be stored.

Discrete value variables

These variables generally expand to discrete values, such as the current working directory
Working directory
In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with each process. When the process refers to a file using a simple file name or relative path , the reference is interpreted relative to the current working directory of...

, the current date, or a random number. Some of these are true environment variables and will be expanded by all functions that handle environment variables. Others, like %CD% simply look like environment variables and will only be expanded by some functions and shells. They are not case sensitive.

%CD%
This variable points to the current directory. Equivalent to the output of the command cd when called without arguments.

%DATE%
This variable expands to the current date. The date is displayed according to the current user's date format
Calendar date
A date in a calendar is a reference to a particular day represented within a calendar system. The calendar date allows the specific day to be identified. The number of days between two dates may be calculated. For example, "24 " is ten days after "14 " in the Gregorian calendar. The date of a...

 preferences.

The following is a way of reformatting the date and time for use in file copies.
The example assumes UK format of day month year and the time is set for a 24 hour clock.


@echo off
echo %DATE% %TIME%
for /F "tokens=1-3 delims=/" %%a in ("%DATE%") do set MTH=%%a& set DAY=%%b& set YR=%%c
for /F "tokens=1-3 delims=:." %%a in ("%TIME%") do set HR=%%a& set MIN=%%b& set SEC=%%c
if "%HR:~0,1%"" " set HR=0%HR:~1,1%
set MYDATE=%YR%%MTH%%DAY%-%HR%%MIN%%SEC%
echo %MYDATE%


%ERRORLEVEL%
This variable points to the current error level. If there was an error in the previous command, this is what you need to check against to find out about that.

%RANDOM%
This variable returns a random number between 0 and 32767

%TIME%
This variable points to the current time. The time is displayed according to the current user's time format preferences.

System path variables

These variables refer to locations of critical operating system resources, and as such generally are not user-dependent.

%AppData%
Contains the full path to the Application Data
Special Folders
On Microsoft Windows, a special folder is a folder which is presented to the user through an interface as an abstract concept, instead of an absolute folder path...

 folder of the logged-in user. Does not work on Windows NT 4.0 SP6 UK.

%LOCALAPPDATA%
This variable is the temporary files of Applications. Its uses include storing of Desktop Themes
Theme (computing)
In computing, a theme is a preset package containing graphical appearance details, used to customize the look and feel of an operating system, widget set or window manager....

, Windows Error Reporting
Windows Error Reporting
Windows Error Reporting is a crash reporting technology introduced by Microsoft with Windows XP and included in later Windows versions and Windows Mobile 5.0 and 6.0. Not to be confused with the Dr...

, Caching and profiles of web browsers.

%ComSpec
ComSpec
ComSpec is one of the environment variables used in MS-DOS and Microsoft Windows, which normally points to the command line interpreter, which is by default command.com in MS-DOS or cmd.exe in Windows NT...

%
This variable contains the full path to the command processor; on Windows NT based operating systems this is cmd.exe, while on Windows 9x and ME it is the DOS command processor, COMMAND.COM.

%PATH%
This variable contains a semicolon-delimited (do not put spaces in between) list of directories in which the command interpreter will search for an executable file that matches the given command. Equivalent to the Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 $PATH variable.

%ProgramFiles%
This variable points to Program Files directory, which stores all the installed program of Windows and others. The default on English-language systems is C:\Program Files. In 64-bit editions of Windows (XP, 2003, Vista), there are also %ProgramFiles(x86)% which defaults to C:\Program Files (x86) and %ProgramW6432% which defaults to C:\Program Files. The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit (this is caused by Windows-on-Windows 64-bit
WoW64
WoW64 is a subsystem of the Windows operating system that is capable of running 32-bit applications and is included on all 64-bit versions of Windows—including Windows XP Professional x64 Edition, IA-64 and x64 versions of Windows Server 2003, as well as 64-bit versions of Windows Vista, Windows...

 redirection).

%CommonProgramFiles%
This variable points to Common Files directory. The default is C:\Program Files\Common Files.

%SystemDrive%
The %SystemDrive% variable is a special system-wide environment variable found on Microsoft
Microsoft
Microsoft Corporation is an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...

 Windows NT
Windows NT
Windows NT is a family of operating systems produced by Microsoft, the first version of which was released in July 1993. It was a powerful high-level-language-based, processor-independent, multiprocessing, multiuser operating system with features comparable to Unix. It was intended to complement...

 and its derivatives. Its value is the drive upon which the system folder was placed. Also see next item.

The value of %SystemDrive% is in most cases C:.

%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
    Windows XP
    Windows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...

    ) and newer versions use \WINDOWS
  • Windows NT 5.0 (Windows 2000
    Windows 2000
    Windows 2000 is a line of operating systems produced by Microsoft for use on personal computers, business desktops, laptops, and servers. Windows 2000 was released to manufacturing on 15 December 1999 and launched to retail on 17 February 2000. It is the successor to Windows NT 4.0, and is the...

    ), Windows NT 4.0 and Windows NT 3.1 use \WINNT
  • Windows NT 3.5x uses \WINNT35


%WinDir%
This variable points to the Windows directory (on Windows NT-based operating systems it is identical to the %SystemRoot% variable, above). If the System is on drive C: then the default values are:
  • C:\WINDOWS on Windows 95
    Windows 95
    Windows 95 is a consumer-oriented graphical user interface-based operating system. It was released on August 24, 1995 by Microsoft, and was a significant progression from the company's previous Windows products...

    , Windows 98
    Windows 98
    Windows 98 is a graphical operating system by Microsoft. It is the second major release in the Windows 9x line of operating systems. It was released to manufacturing on 15 May 1998 and to retail on 25 June 1998. Windows 98 is the successor to Windows 95. Like its predecessor, it is a hybrid...

    , Windows Me
    Windows Me
    Windows Millennium Edition, or Windows Me , is a graphical operating system released on September 14, 2000 by Microsoft, and was the last operating system released in the Windows 9x series. Support for Windows Me ended on July 11, 2006....

    , Windows XP
    Windows XP
    Windows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...

    , Windows Server 2003
    Windows Server 2003
    Windows Server 2003 is a server operating system produced by Microsoft, introduced on 24 April 2003. An updated version, Windows Server 2003 R2, was released to manufacturing on 6 December 2005...

    , Windows Vista
    Windows Vista
    Windows Vista is an operating system released in several variations developed by Microsoft for use on personal computers, including home and business desktops, laptops, tablet PCs, and media center PCs...

    , Windows Server 2008 and Windows 7
  • C:\WINNT for Windows NT 4, and Windows 2000


Note that Windows NT 4 Terminal Server Edition by default installs to C:\WTSRV.

User management variables

These variables store information related to resources and settings owned by various user profile
User profile
A user profile is a collection of personal data associated to a specific user. A profile refers therefore to the explicit digital representation of a person's identity...

s within the system. As a general rule, these variables do not refer to critical system resources or locations that are necessary for the OS to run.

%AllUsersProfile% (%PROGRAMDATA% for Windows Vista, Windows 7)
The %AllUsersProfile%(%PROGRAMDATA%) variable expands to the full path to the All Users profile directory. This profile contains resources and settings that are used by all system accounts. Shortcut
Computer shortcut
A file shortcut in Microsoft Windows is a small file containing a target URI or GUID to an object, or the name of a target program file that the shortcut represents. The shortcut might additionally specify parameters to be passed to the target program when it is run. Each shortcut can have its own...

 links copied to the All Users' Start menu or Desktop folders will appear in every user's Start menu or Desktop
Desktop metaphor
The desktop metaphor is an interface metaphor which is a set of unifying concepts used by graphical user interfaces to help users more easily interact with the computer. The desktop metaphor treats the monitor of a computer as if it is the user's desktop, upon which objects such as documents and...

, respectively.

%UserDomain%
The variable holds the name of the Workgroup
Workgroup
A Workgroup may refer to* a peer-to-peer computer network. See Workgroup * a group of people working together toward a common goal, also known as a working group...

 or Windows Domain
Windows Server domain
A Windows domain is a collection of security principals that share a central directory database. This central database contains the user accounts and security information for...

 to which the current user belongs. The related variable, %LOGONSERVER%, holds the hostname
Hostname
A hostname is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication such as the World Wide Web, e-mail or Usenet...

 of the server that authenticated the current user's logon credentials (name and password). For Home PCs, and PCs in a Workgroup, the authenticating server is usually the PC itself. For PCs in a Windows Domain, the authenticating server is a domain controller
Domain controller
On Windows Server Systems, a domain controller is a server that responds to security authentication requests within the Windows Server domain...

 (a primary domain controller, or PDC, in Windows NT 4-based domains).

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

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

Windows GUI forced variable expansion

In certain cases it is not possible to create file paths containing environment variables using the Windows GUI, and it is necessary to fight with the user interface to make things work as intended.
  • In Windows 7, a shortcut may not contain the variable %USERNAME% in unexpanded form. Trying to create shortcut to \\server\share\accounts\%USERNAME% or C:\users\%USERNAME% will be silently changed to replace %USERNAME% with the account name of the currently logged-in user, when the OK button is pressed on the shortcut properties.
    • This can only be overridden if the %USERNAME% variable is part of a parameter to some other program in the shortcut. For example, %SYSTEMROOT%\Explorer.exe C:\Users\%USERNAME% is not expanded when OK is clicked, but this shortcut is treated as unsafe and displays a warning when opened.

  • In Group Policy Management on Server 2008 R2, a profile folder can not be redirected to a custom folder hierarchy. For example, the desktop can not be redirected to \\server\share\accounts\%USERNAME%\custom\path\desktop. Upon pressing OK, this is silently changed to "Create a folder for each user in the root path" with the path \\server\share\accounts\ pointing to "\username\desktop".
    • This behavior can only be overridden if the path contains a variable or drive letter that is not currently resolvable at the time of editing the GPO. For example if a mapping for drive O: does not exist on the server, then the path O:\folder\%username%\CustomTarget is not expanded when OK is clicked.

  • A domain user account may not contain a profile path or home folder path containing an unexpanded %USERNAME% variable. Upon clicking OK, this is silently replaced with the user's account name.
    • This causes problems for new user creation that is performed by copying an existing user account, if there are additional folders listed after the username in the path. For a pre-existing account with a profile path of \server\share\accounts\DomainUser\profile the Microsoft Management Console doesn't know which part of the path contains the previous user's name and doesn't change the path during the copy, resulting in the new account pointing to the other account's profile/home paths. The profile/home paths must be manually re-edited to point to the correct location.

Default Values on Microsoft Windows

Variable Windows XP Windows Vista/7
%ALLUSERSPROFILE% and %PROGRAMDATA% C:\Documents and Settings\All Users C:\ProgramData
%APPDATA% C:\Documents and Settings\{username}\Application Data C:\Users\{username}\AppData\Roaming
%COMPUTERNAME% {computername} {computername}
%COMMONPROGRAMFILES% C:\Program Files\Common Files C:\Program Files\Common Files
%COMMONPROGRAMFILES(x86)% C:\Program Files (x86)\Common Files C:\Program Files (x86)\Common Files
%COMSPEC% C:\Windows\System32\cmd.exe C:\Windows\System32\cmd.exe
%HOMEDRIVE% C: C:
%HOMEPATH% \Documents and Settings\{username} \Users\{username}
%LOCALAPPDATA% C:\Users\{username}\AppData\Local
%LOGONSERVER% \\{domain_logon_server} \\{domain_logon_server}
%PATH% C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths} C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;{plus program paths}
%PATHEXT% .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.WSF;.WSH .com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc
%PROGRAMFILES% %SystemDrive%\Program Files %SystemDrive%\Program Files
%PROGRAMFILES(X86)% %SystemDrive%\Program Files (x86) (only in 64-bit version) %SystemDrive%\Program Files (x86) (only in 64-bit version)
%PROMPT% Code for current command prompt format. Code is usually $P$G Code for current command prompt format. Code is usually $P$G
{Drive}:\$Recycle.Bin C:\Recycle.Bin C:\$Recycle.Bin
%SystemDrive% C: C:
%SystemRoot% The Windows directory, usually C:\Windows, formerly C:\WINNT %SystemDrive%\Windows
%TEMP% and %TMP% %SystemDrive%\Documents and Settings\{username}\Local Settings\Temp %SystemDrive%\Users\{username}\AppData\Local\Temp
%USERDOMAIN% {userdomain} {userdomain}
%USERDATA% %SystemDrive%\Documents and Settings\{username} %SystemDrive%\Users\{username}
%USERNAME% {username} {username}
%USERPROFILE% %SystemDrive%\Documents and Settings\{username} %SystemDrive%\Users\{username}
%WINDIR% C:\Windows C:\Windows
%PUBLIC% %SystemDrive%\Users\Public
%PROGRAMDATA% %SystemDrive%\ProgramData
%PSModulePath% %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\


In this list, there is no environment variable that refers to the location of the user's My Documents folder, so there is no standard method for setting a program's home directory to be the My Documents folder.

See also

  • List of Unix programs
  • List of DOS commands
  • Environment Modules
    Modules Environment
    The Environment Modules system is a tool to help users manage their Unix or Linux shell environment, by allowing groups of related environment-variable settings to be made or removed dynamically...

  • PWB shell
    PWB shell
    The PWB shell was an early Unix shell.Distributed with some versions of Programmer's Workbench UNIX circa 1975-1977, it was a modified version of the Thompson shell with additional features to increase usability for programming, and was maintained by John Mashey and various others The PWB shell...

    for early (1975-) history of environment variables

Windows

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK