This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Environment variable" – news ·newspapers ·books ·scholar ·JSTOR(May 2023) (Learn how and when to remove this message) |
Anenvironment variable is a user-definablevalue that can affect the way runningprocesses will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to storetemporary files, or the HOME or USERPROFILE variable to find thedirectory structure owned by the user running the process.
They were introduced in their modern form in 1979 withVersion 7 Unix, so are included in allUnixoperating system flavors and variants from that point onward includingLinux andmacOS. FromPC DOS 2.0 in 1982, all succeedingMicrosoft operating systems, includingMicrosoft Windows, andOS/2 also have included them as a feature, although with somewhat different syntax, usage and standard variable names.
In allUnix andUnix-like systems, as well as on Windows, each process has its own separate set of environmentvariables. By default, when a process is created, it inherits a duplicaterun-time environment of its parent process, except for explicit changes made by the parent when it creates the child. At theAPI level, these changes must be done between runningfork
andexec
. Alternatively, fromcommand shells such asbash, a user can change environment variables for a particular command invocation by indirectly invoking it viaenv
or using theENVIRONMENT_VARIABLE=VALUE <command>
notation. A running program can access the values of environment variables for configuration purposes.
Shell scripts andbatch files use environment variables to communicate data and preferences tochild processes. They can also be used to store temporary values for reference later in a shell script. However, in Unix,non-exported variables are preferred for this as they do not leak outside the process.
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. Similarly, changing or removing a variable's value inside aDOS or Windows batch file will change the variable for the duration ofCOMMAND.COM
orCMD.EXE
's existence, respectively.
In Unix, the environment variables are normally initialized during system startup by the systeminitstartup scripts, and hence inherited by all other processes in the system. Users can, and often do, augment them in the profile script for the command shell they are using. In Microsoft Windows, each environment variable's default value is stored in theWindows Registry or set in theAUTOEXEC.BAT
file.
OnUnix, asetuid program is given an environment chosen by its caller, but it runs with different authority from its caller. Thedynamic linker 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.
In general, the collection of environment variables function as anassociative array where both the keys and values are strings. The interpretation of characters in either string differs among systems. When data structures such as lists need to be represented, it is common to use a colon (common on Unix and Unix-like) or semicolon-delineated (common on Windows and DOS) list.
The variables can be used both in scripts and on thecommand line. They are usually referenced by putting special symbols in front of or around the variable name.
It is conventional for environment-variable names to be chosen to be in all upper cases. In programming code generally, this helps to distinguish environment variables from other kinds of names in the code. Environment-variable names are case sensitive on Unix-like operating systems but not on DOS, OS/2, and Windows.
In most Unix and Unix-likecommand-line shells, an environment variable's value is retrieved by placing a$
sign before the variable's name. If necessary, the name can also be surrounded by braces.
To display the user home directory, the user may type:
echo$HOME
In Unix and Unix-like systems, the names of environment variables are case-sensitive.
The commandenv
displays all environment variables and their values. The commandprintenv
can also be used to print a single variable by giving that variable name as the sole argument to the command.
In DOS, OS/2 and Windows command-line interpreters such asCOMMAND.COM
andCMD.EXE
, an environment variable is retrieved by placing a%
sign before and after it.
In DOS, OS/2 and Windows command-line interpreters as well as theirAPI, upper or lower case is not distinguished for environment variable names.
The environment variable namedHOMEDRIVE
contains the drive letter (plus its trailing:
colon) of the user's home directory, whilstHOMEPATH
contains the full path of the user's home directory within that drive.
So to see the home drive and path, the user may type this:
ECHO%HOMEDRIVE%%HOMEPATH%
The commandSET
(with no arguments) displays all environment variables and their values. InWindows NT and laterset
can also be used to print all variables whose name begins with a given prefix by giving the prefix as the sole argument to the command.
InWindows PowerShell, the user may type any of the following:
echo$env:homedrive$env:homepathWrite-Output$env:homedrive$env:homepath"$env:homedrive$env:homepath"
In PowerShell, upper or lower case is not distinguished for environment variable names.
The following command displays all environment variables and their values:
get-childitemenv:
The commandsenv
andset
can be used to set environment variables and are often incorporated directly into the shell.
The following commands can also be used, but are often dependent on a certain shell.
VARIABLE=value # (there must be no spaces around the equals sign)exportVARIABLE # forBourne and related shells
exportVARIABLE=value # forksh,bash, and related shells
setenvVARIABLEvalue # forcsh and related shells
A few simple principles govern how environment variables achieve their effect.
Environment variables are local to the process in which they were set. If two shell processes are spawned and the value of an environment variable is changed in one, that change will not be seen by the other.
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 byforking, then the child adjusts the environment as needed and lastly the childreplaces itself with the program to be called. This procedure gives the calling program control over the environment of the called program.
In Unix shells, variables may be assigned without theexport
keyword. Variables defined in this way are displayed by theset
command, but arenot true environment variables, as they are stored only by the shell and are unknown to all other processes. Theprintenv
command will not display them, and child processes do not inherit them.
VARIABLE=value
The prefix syntax exports a "true" environment variable to a child process without affecting the current process:[1]
VARIABLE=value program_name [arguments]
The persistence of an environment variable can be session-wide or system-wide.
unset
is a builtin command implemented by both theBourne shell family (sh
,ksh
,bash
, etc.) and theC shell family (csh, tcsh, etc.) ofUnix command line shells. It unsets a shell variable, removing it from memory and the shell's exported environment. It is implemented as ashell builtin, because it directly manipulates the internals of the shell.[2][3] Read-only shell variables cannot be unset. If one tries to unset a read-only variable, theunset
command will print an error message and return a non-zero exit code.
In DOS, OS/2 and Windows command-line interpreters such asCOMMAND.COM
andCMD.EXE
, theSET
command is used to assign environment variables and values using the following arguments:
SETVARIABLE=value
An environment variable is removed via:
SETVARIABLE=
TheSET
command without any arguments displays all environment variables along with their values;SET " "
, zero or more spaces, will include internal variables too. InCMD.EXE
, it is possible to assign local variables that will not be global using theSETLOCAL
command andENDLOCAL
to restore the environment.
Use theswitch/?
to display the internaldocumentation, or use theviewerhelp
:
SET/? HELP SETSETLOCAL /? HELP SETLOCAL
InPowerShell, the assignment follows a syntax similar to Unix:
$env:VARIABLE="VALUE"
Examples of environment variables include:
PATH
: a list of directory paths. When theuser types a command without providing the full path, this list is checked to see whether it contains a path that leads to the command.HOME
(Unix-like) andUSERPROFILE
(Microsoft Windows): indicate where a user'shome directory is located in thefile system.HOME/{.AppName}
(Unix-like) andAPPDATA\{DeveloperName\AppName}
(Microsoft Windows): for storing application settings. Many applications incorrectly useUSERPROFILE
for application settings in Windows:USERPROFILE
should only be used in dialogs that allow user to choose between paths likeDocuments/Pictures/Downloads/Music
; for programmatic purposes,APPDATA
(for roaming application settings shared across multiple devices),LOCALAPPDATA
(for local application settings) orPROGRAMDATA
(for application settings shared between multiple OS users) should be used.[4]TERM
(Unix-like): specifies the type ofcomputer terminal orterminal emulator being used (e.g.,vt100
ordumb
).PS1
(Unix-like): specifies how the prompt is displayed in theBourne shell and variants.MAIL
(Unix-like): used to indicate where a user's mail is to be found.TEMP
: location where processes can store temporary files.$PATH
%PATH%
variable.$HOME
getpwuid
andgetuid
,$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
$DISPLAY
$LD_LIBRARY_PATH
exec
, before searching in any other directories.$LIBPATH
or$SHLIB_PATH
$LD_LIBRARY_PATH
typically used on older Unix versions.$LANG, $LC_ALL, $LC_...
$LANG
is used to set to the defaultlocale. For example, if the locale values arept_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
,$LC_DATE
etc.).$LC_ALL
can be used to force the same locale for all aspects.$TZ
/usr/share/zoneinfo
).$BROWSER
%s
token may be present to specify where the URL should be placed; otherwise the browser should be launched with the URL as the first argument.[5][6][7][8][9]Under DOS, themaster environment is provided by the primary command processor, which inherits thepre-environment defined inCONFIG.SYS
when first loaded. Its size can be configured through theCOMMAND /E:n
parameter between 160[10] and 32767[10] bytes.Local environment segments inherited to child processes are typically reduced down to the size of the contents they hold. Some command-line processors (like4DOS) allow to define a minimum amount of free environment space that will be available when launching secondary shells.[10] While the content of environment variables remains unchanged upon storage, their names (without the "%
") are always converted to uppercase, with the exception ofpre-environment variables defined via theCONFIG.SYS
directiveSET
underDR DOS 6.0 and higher[11][12] (and only withSWITCHES=/L
(for "allow lowercase names") underDR-DOS 7.02 and higher).[10][13] In principle,MS-DOS 7.0 and higher also supports lowercase variable names (%windir%
), but provides no means for the user to define them. Environment variable names containing lowercase letters are stored in the environment just like normal environment variables, but remain invisible to most DOS software, since they are written to expect uppercase variables only.[10][11][12] Some command processors limit the maximum length of a variable name to 80 characters.[10] While principally only limited by the size of theenvironment segment, some DOS and 16-bit Windows programs[10][nb 1] do not expect the contents of environment variables to exceed 128 characters. DR-DOSCOMMAND.COM
supports environment variables up to 255,4DOS even up to 512 characters.[10] SinceCOMMAND.COM
can be configured (via/L:128..1024
) to support command lines up to 1024 characters internally under MS-DOS 7.0 and higher, environment variables should be expected to contain at least 1024 characters as well. In some versions of DR-DOS, the environment passed to drivers, which often do not need their environment after installation, can be shrunken orrelocated throughSETENV
orINSTALL[HIGH]
/LOADHIGH
options/Z
(zero environment),/D[:loaddrive]
(substitute drive, e.g.B:TSR.COM
) and/E
(relocate environment above program) in order to minimize the driver's effectively resulting residentmemory footprint.[14][13][11][15][16][17]
In batch mode, non-existent environment variables are replaced by a zero-length string.
Standard environment variables orreserved environment variables include:
%APPEND%
(supported since DOS 3.3)APPEND /E
command, which also ensures that the directory names are converted into uppercase. Some DOS software actually expects the names to be stored in uppercase and the length of the list not to exceed 121[10] characters, therefore the variable is best not modified via theSET
command.Long filenames containing spaces or other special characters must not be quoted ("
).%CONFIG%
(supported sinceMS-DOS 6.0 andPC DOS 6.1, also supported byROM-DOS[18])IO.SYS
,IBMBIO.COM
, etc.) to the name defined by the correspondingCONFIG.SYS
directiveMENUITEM
before launching the primary command processor. Its main purpose is to allow further special cases inAUTOEXEC.BAT
and similar batchjobs depending on the selected option at boot time. This can be emulated under DR-DOS by utilizing theCONFIG.SYS
directiveSET
likeSET CONFIG=1
.%CMDLINE%
(introduced with4DOS, also supported sinceMS-DOS 7.0)COMMAND.COM
still only supports a maximum of 126 characters at the prompt by default (unless overridden with/U:128..255
to specify the size of the command line buffer), but nevertheless internal command lines can become longer through f.e. variable expansion (depending on/L:128..1024
to specify the size of the internal buffer). In addition to the command-line length byte in the PSP, the PSP command line is normally limited byASCII-13, and command lines longer than 126 characters will typically be truncated by having an ASCII-13 inserted at position 127,[12] but this cannot be relied upon in all scenarios.[12][nb 2] The variable will be suppressed for external commands invoked with a preceding@
-symbol like in@XCOPY ...
for backward compatibility and in order to minimize the size of the environment when loading non-relocatingterminate-and-stay-resident programs. Some beta versions ofWindows Chicago used%CMDLINE%
to store only the remainder of the command line excessing 126 characters instead of the complete command line.[11][12]%COMSPEC%
(supported since DOS 2.0)C:\COMMAND.COM
orC:\DOS\COMMAND.COM
. It must not containlong filenames, but under DR-DOS it may containfile anddirectory passwords. It is set up by the primary command processor to point to itself (typically reflecting the settings of theCONFIG.SYS
directiveSHELL
), so that the resident portion of the command processor can reload its transient portion from disk after the execution of larger programs. The value can be changed at runtime to reflect changes in the configuration, which would require the command processor to reload itself from other locations. The variable is also used when launching secondary shells.%COPYCMD%
(supported sinceMS-DOS 6.2 andPC DOS 6.3, also supported byROM-DOS[18])/Y
switch (to assume "Yes" on queries) as the default for theCOPY
,XCOPY
, andMOVE
commands. A default of/Y
can be overridden by supplying the/-Y
switch on the command line. The/Y
switch instructs the command to replace existing files without prompting for confirmation.%DIRCMD%
(supported sinceMS-DOS 5.0 andPC DOS 5.0, also supported byROM-DOS[18])DIR
command, including file specifications. Preset default switches can be overridden by providing the negative switch on the command line. For example, if%DIRCMD%
contains the/W
switch, then it can be overridden by usingDIR /-W
at the command line. This is similar to the environment variable%$DIR%
underDOS Plus[19] and a facility to define default switches forDIR
through its/C
or/R
switches underDR-DOSCOMMAND.COM
.[11]%DIRCMD%
is also supported by the externalSDIR.COM
/DIR.COM
Stacker commands underNovell DOS 7 and higher.[11]%LANG%
(supported sinceMS-DOS 7.0)%LANGSPEC%
(supported sinceMS-DOS 7.0)%NO_SEP%
(supported sincePC DOS 6.3 andDR-DOS 7.07)SET NO_SEP=ON
orSET NO_SEP=1
under PC DOS. DR-DOS additionally allows to override the system's thousands-separator displayed as in f.e.SET NO_SEP=.
.[10]%PATH%
(supported since DOS 2.0)$PATH
variable (but some DOS and Windows applications also use the list to search for data files similar to$LD_LIBRARY_PATH
on Unix-like systems). It is usually changed via thePATH
(orPATH /E
underMS-DOS 6.0) command, which also ensures that the directory names are converted into uppercase. Some DOS software actually expects the names to be stored in uppercase and the length of the list not to exceed 123[10] characters,[nb 1] therefore the variable should better not be modified via theSET
command.[10]Long filenames containing spaces or other special characters must not be quoted ("
). By default, the current directory is searched first, but some command-line processors like4DOS allow ".
" (for "current directory") to be included in the list as well in order to override this search order; some DOS programs are incompatible with this extension.[10]%PROMPT%
(supported since DOS 2.0)$
-tokenized string defining the display of theprompt. It is usually changed via thePROMPT
command.%TEMP%
(and%TMP%
)%TEMP%
, whereas third-party programs also use%TMP%
. Typically%TEMP%
takes precedence over%TMP%
.TheDR-DOS family supports a number of additionalstandard environment variables including:
%BETA%
COMMAND.COM
at the startup of secondary shells.[20]%DRDOSCFG%
/%NWDOSCFG%
/%OPENDOSCFG%
\
") where to search for.INI
and.CFG
configuration files (that is, DR-DOS application specific files likeTASKMGR.INI
,TASKMAX.INI
,VIEWMAX.INI
,FASTBACK.CFG
etc., class specific files likeCOLORS.INI
, or global files likeDRDOS.INI
,NWDOS.INI
,OPENDOS.INI
, orDOS.INI
), as used by theINSTALL
andSETUP
commands and various DR-DOS programs likeDISKOPT
,DOSBOOK
,EDIT
,FBX
,FILELINK
,LOCK
,SECURITY.OVL
/NWLOGIN.EXE
,SERNO
,TASKMAX
,TASKMGR
,VIEWMAX
, orUNDELETE
.[11] It must not containlong filenames.%DRCOMSPEC%
%COMSPEC%
variable, optionally includingfile anddirectory passwords. Alternatively, it can hold a special value of "ON
" or "1
" in order to enforce the usage of the%COMSPEC%
variable even in scenarios where the%COMSPEC%
variable may point to the wrong command-line processor, for example, when running some versions of the DR-DOSSYS
command under a foreign operating system.[22]%DRSYS%
ON
" or "1
" will force some versions of the DR-DOSSYS
command to work under foreign operating systems instead of displaying a warning.[22]%FBP_USER%
FBX
and{user}.FB
configuration files underNovell DOS 7.[11]%HOMEDIR%
%INFO%
COMMAND.COM
this variable defines the string displayed by the$I
token of thePROMPT
command.[20] It can be used, for example, to inform the user how to exit secondary shells.%LOGINNAME%
COMMAND.COM
this variable defines the user name displayed by the$U
token of thePROMPT
command, as set up by f.e. login scripts forNovell NetWare.[10][11][20] See also the similarly named pseudo-variable%LOGIN_NAME%
.%MDOS_EXEC%
ON
" or "OFF
" underMultiuser DOS. If enabled, the operating system permits applications to shell out to secondary shells with theDOS Program Area (DPA) freed in order to have maximum DOS memory available for secondary applications instead of running them in the same domain as under DOS.[23][24]%NOCHAR%
[Y,N]
queries, thereby overriding the current system default (typically "N
" in English versions of DR-DOS). If it contains a string, only the first character, uppercased, will be taken. Some commands also support a command line parameter/Y
to automatically assume "Yes" on queries, thereby suppressing such prompts. If, however, the parameter/Y:yn
is used to specify the "Yes"/"No" characters (thereby overriding any%NOCHAR%
setting), queries are not suppressed. See also the relatedCONFIG.SYS
directiveNOCHAR
and the environment variable%YESCHAR%
.[22]%NOSOUND%
ON
" or "1
" will disable default beeps issued by some DR-DOS commands in certain situations such as to inform the user of the completion of some operation, that user interaction is required, or when a wrong key was pressed. Command line options to specifically enable certain beeps will override this setting.%OS%
DOSPLUS
" (DOS Plus 1.2 in DOS emulation), "CPCDOS 4.1
" (DOS Plus 1.2 inCP/M emulation), "DRDOS
" (DR DOS 3.31-6.0,DR DOS Panther,DR DOS StarTrek,DR-DOS 7.02[21]-7.05), "EZDOS
" (EZ-DOS 3.41), "PALMDOS
" and "NetWare PalmDOS
" (PalmDOS 1.0), "NWDOS
" (Novell DOS 7), "NWDOS7
" (Novell DOS 7 Beta), "OPENDOS
" (Caldera OpenDOS 7.01,Caldera DR-OpenDOS 7.02), "CDOS
" (Concurrent DOS,Concurrent DOS XM), "CPCDOS
" (Concurrent PC DOS), "CDOS386
" (Concurrent DOS 386), "DRMDOS
" (DR Multiuser DOS), "MDOS
" (CCI Multiuser DOS),[23] "IMSMDOS
" (IMS Multiuser DOS), "REAL32
" (REAL/32).[11][25] MS-DOSINTERSVR
looks for a value of "DRDOS
" as well.[25] See also the identically named environment variable%OS%
later introduced in theWindows NT family.%PEXEC%
$X
token of thePROMPT
command beforeCOMMAND.COM
displays the prompt after returning from external program execution.[11][21]%SWITCHAR%
/
" (DOS style), "-
" (Unix style) and "[
" (CP/M style). See also the relatedCONFIG.SYS
directiveSWITCHAR
(to set the system's SwitChar setting) and the%/%
system information variable in some issues of DR-DOSCOMMAND.COM
(to retrieve the current setting for portable batchjobs).%TASKMGRWINDIR%
SYSTEM.INI
to be used by the DR-DOSTASKMGR
multitasker is located, overriding the default procedure to locate the file.[11]%VER%
VER
command.[21] It is also used for the$V
token of thePROMPT
command and affects the value returned by thesystem information variable%OS_VERSION%
. Known values include "1.0
" (PalmDOS 1.0), "1.2
" (DOS Plus 1.2 in DOS emulation), "2.0
" (Concurrent DOS 386 2.0), "3.0
" (Concurrent DOS 386 3.0), "3.31
" (DR DOS 3.31), "3.32
" (DR DOS 3.32), "3.33
" (DR DOS 3.33), "3.34
" (DR DOS 3.34), "3.35
" (DR DOS 3.35), "3.40
" (DR DOS 3.40), "3.41
" (DR DOS 3.41,EZ-DOS 3.41), "3.41T
" (DR DOS 3.41T), "4.1
" (Concurrent PC DOS 4.1), "5.0
" (DR DOS 5.0,DR Multiuser DOS 5.0), "5.1
" (Novell DR Multiuser DOS 5.1), "6.0
" (DR Concurrent DOS XM 6.0,DR DOS 6.0), "6.2
" (DR Concurrent DOS XM 6.2), "7
" (Novell DOS 7,Caldera OpenDOS 7.01,DR-DOS 7.02-7.05), "7.00
" (CCI Multiuser DOS 7.00), "7.07
" (DR-DOS 7.07), "7.1
" (IMS Multiuser DOS 7.1), "7.21
" (CCI Multiuser DOS 7.21),[23] "7.22
" (CCI Multiuser DOS 7.22) etc.[11][25][23]%YESCHAR%
[Y,N]
queries, thereby overriding the current system default (typically "Y
" in English versions of DR-DOS). If it contains a string, only the first character, uppercased, will be taken. Some commands also support a command line parameter/Y
to automatically assume "Yes" on queries, thereby suppressing such prompts. If, however, the parameter/Y:y
is used to specify the "Yes" character (thereby overriding any%YESCHAR%
setting), queries are not suppressed. See also the relatedCONFIG.SYS
directiveYESCHAR
and the environment variable%NOCHAR%
.[22]%$CLS%
CLS
command is issued, thereby overriding the internal default ("←[2J
" under DR-DOS, "←E
" underDOS Plus 1.2 on Amstrad machines[19] as well as underConcurrent DOS,Multiuser DOS, andREAL/32 forVT52 terminals, or "←+
" under Multiuser DOS forASCII terminals).[23] If the variable is not defined and noANSI.SYS
console driver is detected, the DR-DOSCOMMAND.COM
will directly clear the screen viaINT 10h/AH=00h
BIOS function, like MS-DOS/PC DOSCOMMAND.COM
does. A special\nnn
-notation foroctal numbers is supported to allow the definition of special characters like ESC (ASCII-27 = "←" = 1Bh = 33o), as f.e. inSET $CLS=\033[2J
. To send the backslash ("\
") itself, it can be doubled "\\
".[11][20][23]%$DIR%
/L
or/W
.[20][19] See also the similar environment variable%DIRCMD%
and theDIR
options/C
and/R
of the DR-DOS COMMAND.COM.[11]%$PAGE%
ON
" or "OFF
" for pagination control. Setting this to "ON
" has the same affect as adding/P
to commands supporting it (likeDIR orTYPE).[20][19]%$LENGTH%
/P
option supported by various commands or with automatic pagnination.[20][19] See also the related environment variables%$WIDTH%
and%DIRSIZE%
as well as the similar pseudo-variable%_ROWS%
.%$WIDTH%
DIR /W
orTYPE filename
.[20][19] See also the related environment variables%$LENGTH%
and%DIRSIZE%
as well as the similar pseudo-variable%_COLUMNS%
.%$SLICE%
SLICE
.%$ON%
TYPE wildcard
, for exampleSET $ON=\033[1m
withANSI.SYS loaded orSET $ON=\016
for an IBM orESC/P printer. For the special\nnn
octal notation supported, see%$CLS%
.[11][19] While the variable is undefined by default under DOS Plus and DR-DOS, theMultiuser DOS default for anASCII terminal equalsSET $ON=\033p
.[20][23] See also the related environment variable%$OFF%
.%$OFF%
TYPE wildcard
, for exampleSET $OFF=\033[0m
withANSI.SYS loaded orSET $OFF=\024
for an IBM orESC/P printer. For the special\nnn
octal notation supported, see%$CLS%
.[11][19] While the variable is undefined by default under DOS Plus and DR-DOS, theMultiuser DOS default for anASCII terminal equalsSET $OFF=\033q
.[20][23] See also the related environment variable%$ON%
.%$HEADER%
TYPE
under DR-DOS 7.02 and higher. It can be used for highlighting, pagination or formatting, f.e. when sending the output to a printer, i.e.SET $HEADER=\017
for an IBM orESC/P printer. For the special\nnn
octal notation supported, see%$CLS%
.[20] See also the related environment variable%$FOOTER%
.%$FOOTER%
TYPE
under DR-DOS 7.02 and higher. It is used to return to the normal output format, i.e.SET $FOOTER=\022\014
in the printer example above. For the special\nnn
octal notation supported, see%$CLS%
.[20] See also the related environment variable%$HEADER%
.Datalight ROM-DOS supports a number of additionalstandard environment variables as well including:
%DIRSIZE%
rows[,cols]
forDIR
options/P
and/W
(similar to%$LENGTH%
and%$WIDTH%
under DOS Plus).[18]%NEWFILE%
%TZ%
,%COMM%
,%SOCKETS%
,%HTTP_DIR%
,%HOSTNAME%
and%FTPDIR%
are also used by ROM-DOS.[18]
%BEGINLIBPATH%
%LIBPATH%
variable (which is set during system startup with the specialCONFIG.SYS directiveLIBPATH
). It is possible to specify relative directories here, including ".
" for the current working directory. See also the related environment variable%ENDLIBPATH%
.%ENDLIBPATH%
%BEGINLIBPATH%
, but searchedafter the list of directories in%LIBPATH%
.These environment variables refer to locations of critical operating system resources, and as such generally are not user-dependent.[26]
%APPDATA%
%LOCALAPPDATA%
%ComSpec%
/%COMSPEC%
%ComSpec%
variable contains the full path to the command processor; on the Windows NT family of operating systems, this iscmd.exe, while onWindows 9x,%COMSPEC%
isCOMMAND.COM.%OS%
%OS%
variable contains a symbolic name of the operating system family to distinguish between differing feature sets inbatchjobs. It resembles an identically named environment variable%OS%
found in all DOS-related operating systems ofDigital Research-origin like Concurrent DOS,Multiuser DOS, REAL/32,DOS Plus,DR DOS, Novell DOS and OpenDOS.%OS%
always holds the string "Windows_NT
" on theWindows NT family.[27]%PATH%
%PATH%
variable, but only at one level of indirection. If this sub-path environment variable itself contains an environment variable representing a path,%PATH%
will not expand properly in the variable substitution. Equivalent to theUnix$PATH
variable.%PROCESSOR_ARCHITECTURE%
,%PROCESSOR_ARCHITEW6432%
,%PROCESSOR_IDENTIFIER%
,%PROCESSOR_LEVEL%
,%PROCESSOR_REVISION%
%PUBLIC%
%PUBLIC%
variable (introduced with Vista) points to thePublic (pseudo) user profile directory "C:\Users\Public
".%ProgramFiles%
,%ProgramFiles(x86)%
,%ProgramW6432%
%ProgramFiles%
variable points to theProgram Files directory, which stores all the installed programs 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 byWindows-on-Windows 64-bit redirection[28]).%CommonProgramFiles%
,%CommonProgramFiles(x86)%
,%CommonProgramW6432%
C:\Program Files\Common 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 byWindows-on-Windows 64-bit redirection).%OneDrive%
%OneDrive%
variable is a special system-wide environment variable found on Windows NT and its derivatives. Its value is the path of where (if installed and setup) the Onedrive directory is located. The value of%OneDrive%
is in most cases "C:\Users\{Username}\OneDrive\
".%SystemDrive%
%SystemDrive%
variable is a special system-wide environment variable found on Windows NT and its derivatives. Its value is the drive upon which the system directory was placed. The value of%SystemDrive%
is in most cases "C:
".%SystemRoot%
%SystemRoot%
variable is a special system-wide environment variable found on the Windows NT family of operating systems. Its value is the location of the system directory, 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:\WINDOWS
".\WINNT
".\WINNT35
".\WTSRV
".%windir%
%SystemRoot%
variable).Windows 95–98 andWindows ME are, by default, installed in "C:\Windows
". For other versions of Windows, see the%SystemRoot%
entry above.User management variables[citation needed] store information related to resources and settings owned by varioususer profiles 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%
since Windows Vista)%USERDOMAIN%
%LOGONSERVER%
, holds thehostname of the server that authenticated the current user's login 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 adomain controller (a primary domain controller, or PDC, in Windows NT 4-based domains).%USERPROFILE%
NTUSER
). Users can also use the%USERNAME%
variable to determine the active users login identification.Optional System variables[citation needed] are not explicitly specified by default but can be used to modify the default behavior of certain built-in console commands. These variables also do not need to be explicitly specified as command line arguments.
The following tables shows typical default values of certain environment variables under English versions of Windows as they can be retrieved underCMD
.
(Some of these variables are also defined when runningCOMMAND.COM
under Windows, but differ in certain important details: UnderCOMMAND.COM
, the names of environment variable are always uppercased. Some, but not all variables contain short8.3 rather thanlong file names. While some variables present in theCMD
environment are missing, there are also some variables specific to theCOMMAND
environment.)
Variable | Locale specific | Windows XP (CMD) | Windows Vista and later (CMD) |
---|---|---|---|
%ALLUSERSPROFILE%[29] | Yes | C:\Documents and Settings\All Users | C:\ProgramData[29] |
%APPDATA%[29] | Yes | C:\Documents and Settings\%USERNAME%\Application Data | C:\Users\%USERNAME%\AppData\Roaming[29] |
%CommonProgramFiles%[29] | Yes | C:\Program Files\Common Files | C:\Program Files\Common Files[29] |
%CommonProgramFiles(x86)%[29] | Yes | C:\Program Files (x86)\Common Files(only in 64-bit version) | C:\Program Files (x86)\Common Files(only in 64-bit version)[29] |
%CommonProgramW6432%[29] | Yes | %CommonProgramW6432%(not supported, not replaced by any value) | C:\Program Files\Common Files(only in 64-bit version)[29] |
%COMPUTERNAME% | No | {computername} | {computername} |
%ComSpec% | No | C:\Windows\System32\cmd.exe | C:\Windows\System32\cmd.exe |
%HOMEDRIVE%[29] | No | C: | C:[29] |
%HOMEPATH%[29] | Yes | \Documents and Settings\%USERNAME% | \Users\%USERNAME%[29] |
%LOCALAPPDATA%[29] | Yes | %LOCALAPPDATA%(not supported, not replaced by any value) | C:\Users\%USERNAME%\AppData\Local[29] |
%LOGONSERVER% | No | \\{domain_logon_server} | \\{domain_logon_server} |
%PATH% | Yes | 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% | No | .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.WSF;.WSH | .com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc |
%ProgramData%[29] | Yes | %ProgramData%(not supported, not replaced by any value) | %SystemDrive%\ProgramData[29] |
%ProgramFiles%[29] | Yes | %SystemDrive%\Program Files | %SystemDrive%\Program Files[29] |
%ProgramFiles(x86)%[29] | Yes | %SystemDrive%\Program Files (x86)(only in 64-bit version) | %SystemDrive%\Program Files (x86)(only in 64-bit version)[29] |
%ProgramW6432%[29] | Yes | %ProgramW6432%(not supported, not replaced by any value) | %SystemDrive%\Program Files(only in 64-bit version)[29] |
%PROMPT% | No | Code for current command prompt format, usually$P$G | Code for current command prompt format, usually$P$G |
%PSModulePath% | %PSModulePath%(not supported, not replaced by any value) | %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\ | |
%PUBLIC%[29] | Yes | %PUBLIC%(not supported, not replaced by any value) | %SystemDrive%\Users\Public[29] |
%SystemDrive%[29] | No | C: | C:[29] |
%SystemRoot%[29] | No | The Windows directory, usuallyC:\Windows, formerlyC:\WINNT | %SystemDrive%\Windows[29] |
%TEMP%[29] and%TMP%[29] | Yes | %SystemDrive%\Documents and Settings\%USERNAME%\Local Settings\Temp | %SystemRoot%\TEMP (for system environment variables%TMP% and%TEMP%), %USERPROFILE%\AppData\Local\Temp[29] (for user environment variables%TMP% and%TEMP%) |
%USERDOMAIN% | No | {userdomain} | {userdomain} |
%USERNAME% | No | {USERNAME} | {USERNAME} |
%USERPROFILE%[29] | Yes | %SystemDrive%\Documents and Settings\%USERNAME% | %SystemDrive%\Users\%USERNAME%[29] |
%windir%[29] | No | %SystemDrive%\WINDOWS | %SystemDrive%\Windows[29] |
In this list, there is no environment variable that refers to the location of the user'sMy Documents directory, so there is no standard method for setting a program's home directory to be theMy Documents directory.
The command processors in DOS and Windows also support pseudo-environment variables. These are values that are fetched like environment variables, but are not truly stored in the environment but computed when requested.
Besides true environment variables, which are statically stored in the environment until changed or deleted, a number of pseudo-environment variables exist for batch processing.
The so-calledreplacement parameters orreplaceable parameters (Microsoft / IBM terminology) akareplacement variables (Digital Research / Novell / Caldera terminology)[21] orbatch file parameters (JP Software terminology)[10]%1
..%9
and%0
can be used to retrieve the calling parameters of a batchjob, seeSHIFT
. In batchjobs, they can be retrieved just like environment variables, but are not actually stored in the environment.
Some command-line processors (likeDR-DOSCOMMAND.COM
,[21]Multiuser DOSMDOS.COM
/TMP.EXE
(Terminal Message Process), JP Software4DOS,4OS2,4NT,Take Command and Windowscmd.exe) support a type of pseudo-environment variables namedsystem information variables (Novell / Caldera terminology)[21] orinternal variables (JP Software terminology),[10] which can be used to retrieve various possibly dynamic, but read-only information about the running system in batch jobs. The returned values represent the status of the system in the moment these variables are queried; that is, reading them multiple times in a row may return different values even within the same command; querying them has no direct effect on the system. Since they are not stored in the environment, they are not listed bySET and do not exist for external programs to retrieve. If a true environment variable of the same name is defined, it takes precedence over the corresponding variable until the environment variable is deleted again. They are not case-sensitive.While almost all such variables are prefixed with anunderscore ("_
") by 4DOS etc. by convention (f.e.%_SECOND%
),[10] they are not under DR-DOSCOMMAND.COM
(f.e.%OS_VERSION%
).
In addition, 4DOS, 4OS2, 4NT, and Take Command also support so calledvariable functions,[10] including user-definable ones. They work just likeinternal variables, but can take optional parameters (f.e.%@EVAL[]%
) and may even change the system status depending on their function.
System information variables supported by DR-DOSCOMMAND.COM
:
%AM_PM%
am
" or "pm
" in the English version. It resembles an identically namedidentifier variable inNovell NetWare login scripts.%DAY%
01
".."31
". See also the similar pseudo-variable%_DAY%
. It resembles an identically namedidentifier variable inNovell NetWare login scripts.%DAY_OF_WEEK%
Sun
", "Mon
", "Tue
", "Wed
", "Thu
", "Fri
", or "Sat
" in the English version. It resembles an identically namedidentifier variable inNovell NetWare login scripts.%ERRORLEVEL%
COMMAND.COM
of DR-DOS 7.02 and higher, this pseudo-variable returns the last error level returned by an external program or theRETURN
command, f.e. "0
".."255
".[30][31] See also the identically named pseudo-variable%ERRORLEVEL%
under Windows and theIF ERRORLEVEL
conditional command.%ERRORLVL%
000
".."255
".[30][31] UnderMultiuser DOS, this is a true environment variable automatically updated by the shell to the return code of exiting programs.[23] See also the related pseudo-variable%ERRORLEVEL%
under DR-DOS and theIF ERRORLEVEL
command.%GREETING_TIME%
morning
", "afternoon
", or "evening
" in the English version. It resembles an identically namedidentifier variable inNovell NetWare login scripts.%HOUR%
1
".."12
". It resembles an identically namedidentifier variable inNovell NetWare login scripts.%HOUR24%
00
".."23
". It resembles an identically namedidentifier variable inNovell NetWare login scripts. See also the similar pseudo-variable%_HOUR%
.%MINUTE%
00
".."59
". It resembles an identically namedidentifier variable inNovell NetWare login scripts. See also the similar pseudo-variable%_MINUTE%
.%MONTH%
01
".."12
". It resembles an identically namedidentifier variable inNovell NetWare login scripts. See also the similar pseudo-variable%_MONTH%
.%MONTH_NAME%
January
", "February
", "March
", "April
", "May
", "June
", "July
", "August
", "September
", "October
", or "December
" in the English version. It resembles an identically namedidentifier variable inNovell NetWare login scripts.%NDAY_OF_WEEK%
1
".."7
" (with "1
" for Sunday). It resembles an identically namedidentifier variable inNovell NetWare login scripts.%OS_VERSION%
%VER%
. If%VER%
is not defined,%OS_VERSION%
returns "off
". It resembles an identically namedidentifier variable inNovell NetWare login scripts, which may return versions also for non-DR-DOS versions of DOS.%SECOND%
00
".."59
". It resembles an identically namedidentifier variable inNovell NetWare login scripts. See also the similar pseudo-variable%_SECOND%
.%SHORT_YEAR%
93
".."99
", "00
".."92
". It resembles an identically namedidentifier variable inNovell NetWare login scripts.%YEAR%
and%_YEAR%
%YEAR%
pseudo-variable returns the year of the current date in a 4-digit format, f.e. "1980
".."2099
". It resembles an identically namedidentifier variable inNovell NetWare login scripts. DR-DOS 7.02 and higher added%_YEAR%
for compatibility with4DOS, returning the same value.[10]%/%
COMMAND.COM
of DR-DOS 7.02 and higher, this pseudo-variable returns the currentSwitChar setting of the system, either "/
" (DOS style) or "-
" (Unix style).[32][33] See also the relatedCONFIG.SYS
directiveSWITCHAR and the environment variable%SWITCHAR%
.%_CODEPAGE%
1
".."65533
"), f.e. "437
", "850
", "858
". This variable was originally introduced by4DOS,[10] but also became available withCOMMAND.COM
since DR-DOS 7.02. See also theCHCP
command.%_COLUMNS%
40
", "80
", "132
", etc. This variable was originally introduced by4DOS,[10] but also became available withCOMMAND.COM
since DR-DOS 7.02. See also a similar environment variable%$WIDTH%
under DOS Plus.%_COUNTRY%
1
".."65534
"), f.e. "1
" for USA, "44
" for UK, "49
" for Germany, "20049
" withISO 8601, "21049
" with ISO 8601 andEuro support.[33][34] This variable was originally introduced by4DOS,[10] but also became available withCOMMAND.COM
since DR-DOS 7.02. See also theCONFIG.SYS
directiveCOUNTRY
.%_DAY%
1
".."31
". This variable was originally introduced by4DOS,[10] but also became available withCOMMAND.COM
since DR-DOS 7.02. See also the similar pseudo-variable%DAY%
.%_HOUR%
0
".."23
". This variable was originally introduced by4DOS,[10] but also became available withCOMMAND.COM
since DR-DOS 7.02. See also the similar pseudo-variable%HOUR24%
.%_MINUTE%
0
".."59
". This variable was originally introduced by4DOS,[10] but also became available withCOMMAND.COM
since DR-DOS 7.02. See also the similar pseudo-variable%MINUTE%
.%_MONTH%
1
".."12
". This variable was originally introduced by4DOS,[10] but also became available withCOMMAND.COM
since DR-DOS 7.02. See also the similar pseudo-variable%MONTH%
.%_ROWS%
25
", "43
", "50
", etc. This variable was originally introduced by4DOS,[10] but also became available withCOMMAND.COM
since DR-DOS 7.02. See a similar environment variable%$LENGTH%
under DOS Plus.%_SECOND%
0
".."59
". This variable was originally introduced by4DOS,[10] but also became available withCOMMAND.COM
since DR-DOS 7.02. See also the similar pseudo-variable%SECOND%
.System information variables supported by DR-DOSCOMMAND.COM
with networking loaded:
%LOGIN_NAME%
NETX
, but it will also work withPersonal NetWare'sODI/VLM if the current drive is a PNW-mapped drive (otherwise an empty string is returned). See also the similarly named environment variable%LOGINNAME%
.%P_STATION%
????????????
". The value depends on theMAC address of the network adapter, but can be overridden. It resembles an identically namedidentifier variable inNovell NetWare login scripts.%STATION%
1
" for the first client. The numbers are assigned by the file server and remain static for as long as theIPX connection remains established. It resembles an identically namedidentifier variable inNovell NetWare login scripts.%FULL_NAME%
%LOGIN_NAME%
.Dynamic environment variables (also namedinternal variables orsystem information variables under DOS) are pseudo-environment variables supported byCMD.EXE
when command-line extensions are enabled, and they expand to various discrete values whenever queried, that is, their values can change when queried multiple times even within the same command. While they can be used in batch jobs and at the prompt, they are not stored in the environment. Consequently, they are neither listed bySET
nor do they exist for external programs to read. They are not case-sensitive.
Indirectly, they are also supported under Windows'COMMAND.COM
, which has been modified to internally callCMD.EXE
to execute the commands.
%CD%
CD
when called without arguments. While a long filename can be returned underCMD.EXE
depending on the current directory, the fact that the current directory will always be in8.3 format underCOMMAND.COM
will cause it to return a short filename underCOMMAND.COM
, even whenCOMMAND
internally callsCMD
.%CMDCMDLINE%
CMD.EXE
, f.e. "C:\Windows\system32\cmd.exe
". Under Windows'COMMAND.COM
, this may return something like "C:\Windows\system32\cmd.exe /c ...
" due to the fact thatCOMMAND.COM
callsCMD.EXE
internally.%CMDEXTVERSION%
CMD.EXE
, if enabled (e.g. "1
" underWindows NT, "2
" underWindows 2000 andWindows XP).%DATE%
%ERRORLEVEL%
0
" and "255
" (without leading zeros).[30][35][31] External commands and some internal commands set error levels upon execution. See also the identically named pseudo-variable%ERRORLEVEL%
under DR-DOS and theIF ERRORLEVEL
command.%HIGHESTNUMANODENUMBER%
%RANDOM%
0
" and "32767
".%TIME%
%TIME%
and%DATE%
variables are both used, it is important to read them both in this particular order in rapid succession in order to avoid midnight-rollover problems.Unix-like shells have similar dynamically generated variables, bash's$RANDOM
being a well-known example. However, since these shells have a concept of local variables, they are described as special local variables instead.[36]
Standardizing a BROWSER environment variable. Eric Raymond is promoting the use of a new environment variable, BROWSER, to complement the existing PAGER, MAILER, and EDITOR variables. This effort is being tested as an experiment in hacking social systems.
Env::Browser - Process environment variable $BROWSER and run web browser
The environment variable BROWSER can be set to[…] always choose your desired browser.
{{cite book}}
:|work=
ignored (help) (NB. NWDOSTIP.TXT is a comprehensive work onNovell DOS 7 andOpenDOS 7.01, including the description of many undocumented features and internals. The provided link points to a HTML-converted version of the file, which is part of theMPDOSTIP.ZIP
collection.)[1]4DOS5TIP.TXT
file, which is part of theMPDOSTIP.ZIP
collection.)[2][…] SETENV […] to hide and later restore the […] pre-environment […] By using SETENV.COM you can save some KiloBytes of rare DOS memory […] depending on the number of drivers loaded byINSTALL=/INSTALLHIGH=/HIINSTALL= and the current size of the pre-environment. […] this original […] feature cannot be found in any known memory manager/optimizer. […]
[…] In CTMOUSE.ASM prepareTSR routine I found a comment in regard to the zero-environment. […]DESQview orDRDOS zero-env? […] release environment block […] skip if any problem […] zero-pad forMEM style utilities […]
[…] set DRSYS=ON (optional to tell SYS you are aware of the fact that you're running it in a foreign environment and want to proceed anyway without having to individually ACK some warnings and extra info screens displayed in this scenario otherwise) […]
{{cite book}}
:|work=
ignored (help)[5][6]Archived 2017-09-11 atarchive.today (NB. BATTIPS.TXT is part of MPDOSTIP.ZIP. The provided link points to a HTML-converted older version of the BATTIPS.TXT file.)[7]environ(7)
: user environment – Linux Programmer'sManual – Overview, Conventions and Miscellaneaenviron(7)
– FreeBSD Miscellaneous InformationManualenviron(7)
– Darwin andmacOS Miscellaneous InformationManualenviron(7)
– Solaris 11.4 Standards, Environments, Macros, Character Sets, and Miscellany ReferenceManual