Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.
Contents
- Details
- Use and display
- Assignment
- Unix
- unset command
- DOS OS2 and Windows
- DOS
- OS2
- Windows
- Default values
- Critics
- References
They 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 store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.
They were introduced in their modern form in 1979 with Version 7 Unix, so are included in all Unix operating system flavors and variants from that point onward including Linux and macOS. From PC DOS 2.0 in 1982, all succeeding Microsoft operating systems including Microsoft Windows, and OS/2 also have included them as a feature, although with somewhat different syntax, usage and standard variable names.
Details
In all Unix and Unix-like systems, each process has its own separate 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. At the API level, these changes must be done between running fork
and exec
. Alternatively, from command shells such as bash, a user can change environment variables for a particular command invocation by indirectly invoking it via env
or using the ENVIRONMENT_VARIABLE=VALUE <command>
notation. A running program can access the values of environment variables for configuration purposes.
Examples of environment variables include:
Shell scripts 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 a shell script. However, 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 command shell they are using. In Microsoft Windows, each environment variable's default value is stored in the Windows registry or set in the AUTOEXEC.BAT
file.
On Unix, a setuid program is given an environment chosen by its caller, but it runs with different authority from its caller. The dynamic 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.
Use and display
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 user home directory, in most scripting environments, the user has to type:
In DOS, OS/2 and Windows command-line interpreters such as COMMAND.COM
and cmd.exe
, the user has to type this:
In Windows PowerShell, the user has to type this:
The commands env
, set
, and printenv
display all environment variables and their values. printenv
can also be used to print a single variable by giving that variable name as the sole argument to the command.
Assignment
The commands env
and set
are also used to set environment variables and are often incorporated directly into the shell.
Unix
In Unix, the following commands can also be used, but are often dependent on a certain shell.
VARIABLE=value #export VARIABLE # for Bourne and related shellsexport VARIABLE=value # for ksh, bash, and related shellssetenv VARIABLE value # for csh and related shellsA 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 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.
In Unix and Unix-like systems, the names of environment variables are case-sensitive.
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.
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 persistence of an environment variable can be session-wide or system-wide.
unset command
unset is a builtin command implemented by both the Bourne shell family (sh, ksh, bash, etc.) and the C shell family (csh, tcsh, etc.) of Unix command line shells. It unsets a shell variable, removing it from memory and the shell's exported environment. It is implemented as a shell builtin, because it directly manipulates the internals of the shell.
Read-only shell variables cannot be unset. If one tries to unset a read-only variable, the unset command will print an error message and return a non-zero exit code.
DOS, OS/2 and Windows
In DOS, OS/2 and Windows command-line interpreters such as COMMAND.COM
and cmd.exe
, the SET
command is used to assign environment variables and values using the following arguments:
The SET
command without any arguments displays all environment variables along with their values.
$PATH
%PATH%
variable.$HOME
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
$DISPLAY
$LD_LIBRARY_PATH
exec
, before searching in any other directories.$LANG, $LC_ALL, $LC_...
$LANG
is used to set to the default locale. 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
, $LC_DATE
etc.). $LC_ALL
can be used to force the same locale for all aspects.$TZ
/usr/share/zoneinfo
).DOS
Under DOS the master environment is provided by the primary command processor, which inherits the pre-environment defined in CONFIG.SYS
when first loaded. Its size can be configured through the COMMAND /E:n
parameter between 160 and 32767 bytes. Local environment segments inherited to child processes are typically reduced down to the size of the contents they hold. Some command-line processors (like 4DOS) allow to define a minimum amount of free environment space that will be available when launching secondary shells. While the content of environment variables remains unchanged upon storage, their names (without the "%
") are always converted to uppercase, with the exception of pre-environment variables defined via the CONFIG.SYS
directive SET
under DR DOS 6.0 and higher (and only with SWITCHES=/L
(for "allow lowercase names") under DR-DOS 7.02 and higher). 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. Some command processors limit the maximum length of an variable name to 80 characters. While principally only limited by the size of the environment segment, some DOS and 16-bit Windows programs do not expect the contents of environment variables to exceed 128 characters. DR-DOS COMMAND.COM
supports environment variables up to 255, 4DOS even up to 512 characters. Since COMMAND.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 batch mode, non-existent environment variables are replaced by a zero-length string.
Standard environment variables or reserved 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 characters, therefore the variable is best not modified via the SET
command. Long filenames containing spaces or other special characters must not be quoted ("
).%CONFIG%
(supported since MS-DOS 6.0 and PC DOS 6.1)IO.SYS
, IBMBIO.COM
, etc.) to the name defined by the corresponding CONFIG.SYS
directive MENUITEM
before launching the primary command processor. Its main purpose is to allow further special cases in AUTOEXEC.BAT
and similar batchjobs depending on the selected option at boot time. This can be emulated under DR-DOS by utilizing the CONFIG.SYS
directive SET
like SET CONFIG=1
.%CMDLINE%
(introduced with 4DOS, also supported since MS-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 by ASCII-13, and command lines longer than 126 characters will typically be truncated by having an ASCII-13 inserted at position 127, but this cannot be relied upon in all scenarios. 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-relocating TSRs. Some beta versions of Microsoft Chicago used %CMDLINE%
to store only the remainder of the command line excessing 126 characters instead of the complete command line.%COMSPEC%
(supported since DOS 2.0)C:COMMAND.COM
or C:DOSCOMMAND.COM
. It must not contain long filenames, but under DR-DOS it may contain file and directory passwords. It is set up by the primary command processor to point to itself (typically reflecting the settings of the CONFIG.SYS
directive SHELL
), 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 since MS-DOS 6.2 and PC DOS 6.3)/Y
switch (to assume "Yes" on queries) as the default for the COPY
, XCOPY
, and MOVE
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 since MS-DOS 5.0 and PC DOS 5.0)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 using DIR /-W
at the command line. This is similar to a facility to define default switches for DIR
through its /C
or /R
switches under DR-DOS COMMAND.COM
. %DIRCMD%
is also supported by the external SDIR.COM
/DIR.COM
Stacker commands under Novell DOS 7 and higher.%LANG%
(supported since MS-DOS 7.0)%LANGSPEC%
(supported since MS-DOS 7.0)%NO_SEP%
(supported since PC DOS 6.3 and DR-DOS 7.07)SET NO_SEP=ON
or SET 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=.
.%PATH%
(supported since DOS 2.0)$PATH
variable (but some DOS and Windows applications also use the list to search for data files similar as $LD_LIBRARY_PATH
on Unix-like systems). It is usually changed via the PATH
(or PATH /E
under MS-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 characters, therefore the variable should better not be modified via the SET
command. 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 like 4DOS 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.%PROMPT%
(supported since DOS 2.0)$
-tokenized string defining the display of the prompt. It is usually changed via the PROMPT
command.%TEMP%
(and %TMP%
)%TEMP%
, whereas third-party programs also use %TMP%
. Typically %TEMP%
takes precedence over %TMP%
.The DR-DOS family supports a number of additional standard environment variables including:
%BETA%
COMMAND.COM
at the startup of secondary shells.%DRDOSCFG%
/%NWDOSCFG%
/%OPENDOSCFG%
") where to search for .INI
and .CFG
configuration files (that is, DR-DOS application specific files like TASKMGR.INI
, TASKMAX.INI
, VIEWMAX.INI
, FASTBACK.CFG
etc., class specific files like COLORS.INI
, or global files like DRDOS.INI
, NWDOS.INI
, OPENDOS.INI
, or DOS.INI
), as used by the INSTALL
and SETUP
commands and various DR-DOS programs like DISKOPT
, DOSBOOK
, EDIT
, FBX
, FILELINK
, LOCK
, SECURITY.OVL
/NWLOGIN.EXE
, SERNO
, TASKMAX
, TASKMGR
, VIEWMAX
, or UNDELETE
. It must not contain long filenames.%DRCOMSPEC%
%COMSPEC%
variable, optionally including file and directory 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-DOS SYS
command under a foreign operating system.%DRSYS%
ON
" or "1
" will force some versions of the DR-DOS SYS
command to work under foreign operating systems instead of displaying a warning.%FBP_USER%
FBX
and {user}.FB
configuration files under Novell DOS 7.%HOMEDIR%
%INFO%
COMMAND.COM
this variable defines the string displayed by the $I
token of the PROMPT
command. 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 the PROMPT
command, as set up by f.e. login scripts for Novell NetWare. See also the similarly named pseudo-variable %LOGIN_NAME%
.%MDOS_EXEC%
ON
" or "OFF
" under Multiuser DOS. If enabled, the operating system permits applications to shell out to secondary shells with the DOS 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.%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 related CONFIG.SYS
directive NOCHAR
and the environment variable %YESCHAR%
.%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 in CP/M emulation), "DRDOS
" (DR DOS 3.31-6.0, DR DOS Panther, DR DOS StarTrek, DR-DOS 7.02-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), "IMSMDOS
" (IMS Multiuser DOS), "REAL32
" (REAL/32). MS-DOS INTERSVR
looks for a value of "DRDOS
" as well. See also the identically named environment variable %OS%
later introduced in the Microsoft Windows NT family.%PEXEC%
$X
token of the PROMPT
command before COMMAND.COM
displays the prompt after returning from external program execution.%SWITCHAR%
/
" (DOS style), "-
" (Unix style) and "[
" (CP/M style). See also the related CONFIG.SYS
directive SWITCHAR
(to set the system's SwitChar setting) and the %/%
system information variable in some issues of DR-DOS COMMAND.COM
(to retrieve the current setting for portable batchjobs).%TASKMGRWINDIR%
SYSTEM.INI
to be used by the DR-DOS TASKMGR
multitasker is located, overriding the default procedure to locate the file.%VER%
VER
command. It is also used for the $V
token of the PROMPT
command and affects the value returned by the system 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), "7.22
" (CCI Multiuser DOS 7.22) etc.%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 related CONFIG.SYS
directive YESCHAR
and the environment variable %NOCHAR%
.%$CLS%
CLS
command is issued, thereby overriding the internal default ("←[2J
" under DR-DOS, "←E
" under DOS Plus 1.2 on Amstrad machines as well as under Concurrent DOS, Multiuser DOS, and REAL/32 for VT52 terminals, or "←+
" under Multiuser DOS for ASCII terminals). If the variable is not defined and no ANSI.SYS
console driver is detected, the DR-DOS COMMAND.COM
will directly clear the screen via INT 10h/AH=00h
BIOS function, like MS-DOS/PC DOS COMMAND.COM
does. A special nn
-notation for octal numbers is supported to allow the definition of special characters like ESC (ASCII-27 = "←" = 1Bh = 33o), as f.e. in SET $CLS=033[2J
. To send the backslash ("
") itself, it can be doubled "
".%$DIR%
%$PAGE%
%$LENGTH%
/P
option supported by various commands or with automatic pagnination. See also the related environment variable %$WIDTH%
and a similar pseudo-variable %_ROWS%
.%$WIDTH%
DIR /W
or TYPE filename
. See also the related environment variable %$LENGTH%
and a similar pseudo-variable %_COLUMNS%
.%$SLICE%
%$ON%
TYPE wildcard
, for example SET $ON=033[1m
with ANSI.SYS loaded or SET $ON=016
for an IBM or ESC/P printer. For the special nn
octal notation supported, see %$CLS%
. While the variable is undefined by default under DR-DOS, the Multiuser DOS default for an ASCII terminal equals SET $ON=033p
. See also the related environment variable %$OFF%
.%$OFF%
TYPE wildcard
, for example SET $OFF=033[0m
with ANSI.SYS loaded or SET $OFF=024
for an IBM or ESC/P printer. For the special nn
octal notation supported, see %$CLS%
. While the variable is undefined by default under DR-DOS, the Multiuser DOS default for an ASCII terminal equals SET $OFF=033q
. 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 or ESC/P printer. For the special nn
octal notation supported, see %$CLS%
. 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=022014
in the printer example above. For the special nn
octal notation supported, see %$CLS%
. See also the related environment variable %$HEADER%
.OS/2
%BEGINLIBPATH%
%LIBPATH%
variable (which is set during system startup with the special CONFIG.SYS directive LIBPATH
). It is possible to specify relative directories here, including ".
" for the current working directory. See also the related environment variable %ENDLIBPATH%
.%ENDLIBPATH%
%BEGINLIBPATH%
, but searched after the list of directories in %LIBPATH%
.Windows
System path variables refer to locations of critical operating system resources, and as such generally are not user-dependent.
%APPDATA%
%LOCALAPPDATA%
%ComSpec%
/%COMSPEC%
%ComSpec%
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, %COMSPEC%
is the DOS command processor, COMMAND.COM
.%OS%
%OS%
variable contains a symbolic name of the operating system family to distinguish between differing feature sets in batchjobs. Under Windows NT, Windows 2000, Windows XP and Windows 7, it always holds the string "Windows_NT
". It resembles an identically named environment variable %OS%
found in all DOS-related operating systems of Digital Research-origin like Concurrent DOS, Multiuser DOS, REAL/32, DOS Plus, DR DOS, Novell DOS and OpenDOS.%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 the Unix $PATH
variable.%ProgramFiles%
, %ProgramFiles(x86)%
, %ProgramW6432%
%ProgramFiles%
variable points to the Program 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 by Windows-on-Windows 64-bit redirection).%CommonProgramFiles%
C:Program FilesCommon Files
" in the English version of Windows.%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 Windows NT and its derivatives. 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 NT 5.1 (Windows XP) and newer versions use "WINDOWS
", Windows NT 5.0 (Windows 2000), Windows NT 4.0 and Windows NT 3.1 use "WINNT
", Windows NT 3.5x uses "WINNT35
", and Windows NT 4.0 Terminal Server uses "WTSRV
".%windir%
%SystemRoot%
variable, above). If the system is on drive C:, then the default values are "C:WINDOWS
" on Windows 95, Windows 98, Windows Me, Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008 and Windows 7 and "C:WINNT
" for Windows NT 4, and Windows 2000. Windows NT 4 Terminal Server Edition by default installs to "C:WTSRV
".User management variables store information related to resources and settings owned by various user 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%
for Windows Vista, Windows 7)%USERDOMAIN%
%LOGONSERVER%
, holds the hostname 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 (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 are not explicitly specified by default but can be used to modify the default behaviour of certain built-in console commands. These variables also do not need to be explicitly specified as command line arguments.
Default values
The following tables shows typical default values of certain environment variables under English versions of Windows as they can be retrieved under CMD
.
(Some of these variables are also defined when running COMMAND.COM
under Windows, but differ in certain important details: Under COMMAND.COM
, the names of environment variable are always uppercased. Some, but not all variables contain short 8.3 rather than long file names. While some variables present in the CMD
environment are missing, there are also some variables specific to the COMMAND
environment.)
In this list, there is no environment variable that refers to the location of the user's My Documents directory, so there is no standard method for setting a program's home directory to be the My Documents directory.
DOS
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-called replacement parameters or replaceable parameters (Microsoft / IBM terminology) aka replacement variables (Digital Research / Novell / Caldera terminology) or batch file parameters (JP Software terminology) %1
..%9
and %0
can be used to retrieve the calling parameters of a batchjob, see SHIFT
. In batchjobs, they can be retrieved just like environment variables, but are not actually stored in the environment.
Some command-line processors (like DR-DOS COMMAND.COM
, Multiuser DOS MDOS.COM
/TMP.EXE
(Terminal Message Process), JP Software 4DOS, 4OS2, 4NT, Take Command and Windows CMD.EXE) support a type of pseudo-environment variables named system information variables (Novell / Caldera terminology) or internal variables (JP Software terminology), 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 by SET 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 an underscore ("_
") by 4DOS etc. by convention (f.e. %_SECOND%
), they are not under DR-DOS COMMAND.COM
(f.e. %OS_VERSION%
).
In addition, 4DOS, 4OS2, 4NT, and Take Command also support so called variable functions, including user-definable ones. They work just like internal 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-DOS COMMAND.COM
:
%AM_PM%
am
" or "pm
" in the English version. It resembles an identically named identifier variable in Novell NetWare login scripts.%DAY%
01
".."31
". See also the similar pseudo-variable %_DAY%
. It resembles an identically named identifier variable in Novell NetWare login scripts.%DAY_OF_WEEK%
Sun
", "Mon
", "Tue
", "Wed
", "Thu
", "Fri
", or "Sat
" in the English version. It resembles an identically named identifier variable in Novell 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 the RETURN
command, f.e. "0
".."255
". See also the identically named pseudo-variable %ERRORLEVEL%
under Windows and the IF ERRORLEVEL
command.%ERRORLVL%
000
".."255
". See also the related pseudo-variable %ERRORLEVEL%
under DR-DOS and the IF ERRORLEVEL
command.%GREETING_TIME%
morning
", "afternoon
", or "evening
" in the English version. It resembles an identically named identifier variable in Novell NetWare login scripts.%HOUR%
1
".."12
". It resembles an identically named identifier variable in Novell NetWare login scripts.%HOUR24%
00
".."23
". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable %_HOUR%
.%MINUTE%
00
".."59
". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable %_MINUTE%
.%MONTH%
01
".."12
". It resembles an identically named identifier variable in Novell 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 named identifier variable in Novell NetWare login scripts.%NDAY_OF_WEEK%
1
".."7
" (with "1
" for Sunday). It resembles an identically named identifier variable in Novell NetWare login scripts.%OS_VERSION%
%VER%
. If %VER%
is not defined, %OS_VERSION%
returns "off
". It resembles an identically named identifier variable in Novell NetWare login scripts, which may return versions also for non-DR-DOS versions of DOS.%SECOND%
00
".."59
". It resembles an identically named identifier variable in Novell NetWare login scripts. See also the similar pseudo-variable %_SECOND%
.%SHORT_YEAR%
93
".."99
", "00
".."92
". It resembles an identically named identifier variable in Novell 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 named identifier variable in Novell NetWare login scripts. DR-DOS 7.02 and higher added %_YEAR%
for compatibility with 4DOS, returning the same value.%/%
COMMAND.COM
of DR-DOS 7.02 and higher, this pseudo-variable returns the current SwitChar setting of the system, either "/
" (DOS style) or "-
" (Unix style). See also the related CONFIG.SYS
directive SWITCHAR and the environment variable %SWITCHAR%
.%_CODEPAGE%
1
".."65533
"), f.e. "437
", "850
", "858
". This variable was originally introduced by 4DOS, but also became available with COMMAND.COM
since DR-DOS 7.02. See also the CHCP
command.%_COLUMNS%
40
", "80
", "132
", etc. This variable was originally introduced by 4DOS, but also became available with COMMAND.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
" with ISO 8601, "21049
" with ISO 8601 and Euro support. This variable was originally introduced by 4DOS, but also became available with COMMAND.COM
since DR-DOS 7.02. See also the CONFIG.SYS
directive COUNTRY
.%_DAY%
1
".."31
". This variable was originally introduced by 4DOS, but also became available with COMMAND.COM
since DR-DOS 7.02. See also the similar pseudo-variable %DAY%
.%_HOUR%
0
".."23
". This variable was originally introduced by 4DOS, but also became available with COMMAND.COM
since DR-DOS 7.02. See also the similar pseudo-variable %HOUR24%
.%_MINUTE%
0
".."59
". This variable was originally introduced by 4DOS, but also became available with COMMAND.COM
since DR-DOS 7.02. See also the similar pseudo-variable %MINUTE%
.%_MONTH%
1
".."12
". This variable was originally introduced by 4DOS, but also became available with COMMAND.COM
since DR-DOS 7.02. See also the similar pseudo-variable %MONTH%
.%_ROWS%
25
", "43
", "50
", etc. This variable was originally introduced by 4DOS, but also became available with COMMAND.COM
since DR-DOS 7.02. See a similar environment variable %$LENGTH%
under DOS Plus.%_SECOND%
0
".."59
". This variable was originally introduced by 4DOS, but also became available with COMMAND.COM
since DR-DOS 7.02. See also the similar pseudo-variable %SECOND%
.System information variables supported by DR-DOS COMMAND.COM
with networking loaded:
%LOGIN_NAME%
NETX
, but it will also work with Personal NetWare's ODI/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 the MAC address of the network adapter, but can be overridden. It resembles an identically named identifier variable in Novell NetWare login scripts.%STATION%
1
" for the first client. The numbers are assigned by the file server and remain static for as long as the IPX connection remains established. It resembles an identically named identifier variable in Novell NetWare login scripts.%FULL_NAME%
%LOGIN_NAME%
.Windows
Dynamic environment variables (also named internal variables or system information variables under DOS) are pseudo-environment variables supported by CMD
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 batchjobs and at the prompt, they are not stored in the environment. Consequently, they are neither listed by SET
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 call CMD.EXE
to execute the commands.
%CD%
CD
when called without arguments. While a long filename can be returned under CMD.EXE
depending on the current directory, the fact that the current directory will always be in 8.3 format under COMMAND.COM
will cause it to return a short filename under COMMAND.COM
, even when COMMAND
internally calls CMD
.%CMDCMDLINE%
CMD.EXE
, f.e. "C:Windowssystem32cmd.exe
". Under Windows' COMMAND.COM
, this may return something like "C:Windowssystem32cmd.exe /c ...
" due to the fact that COMMAND.COM
calls CMD.EXE
internally.%CMDEXTVERSION%
CMD.EXE
, if enabled (e.g. "1
" under Windows NT, "2
" under Windows 2000 and Windows XP).%DATE%
%ERRORLEVEL%
0
" and "255
" (without leading zeros). External commands and some internal commands set error levels upon execution. See also the identically named pseudo-variable %ERRORLEVEL%
under DR-DOS and the IF ERRORLEVEL
command.%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.Critics
Some critics warn against overuse of environment variables, because of differences between shell languages, that they are ephemeral and easy to overlook, are specific to a user and not to a program. The recommended alternative is configuration files.