Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Environment variable
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Pseudo-environment variables == <!-- Section header used in redirects --> 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. ==={{anchor|DOS-PSEUDOENV}}DOS === {{anchor|Replacement parameter|Replaceable parameter|Replacement variable|Batch file parameter}}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)<ref name="Caldera_1998_USER"/> or ''[[batch file parameter]]s'' (JP Software terminology)<ref name="4DOS_8.00_HELP"/> <code>%1</code>..<code>%9</code> and <code>%0</code> can be used to retrieve the calling parameters of a batchjob, see <code>[[SHIFT (DOS command)|SHIFT]]</code>. In batchjobs, they can be retrieved just like environment variables, but are not actually stored in the environment. {{anchor|System information variable|Internal variable}} Some command-line processors (like [[DR-DOS]] <code>COMMAND.COM</code>,<ref name="Caldera_1998_USER"/> [[Multiuser DOS]] <code>MDOS.COM</code>/<code>[[TMP.EXE]]</code> (Terminal Message Process), JP Software [[4DOS]], [[4OS2]], [[4NT (shell)|4NT]], [[Take Command (command line interpreter)|Take Command]] and Windows [[cmd.exe]]) support a type of pseudo-environment variables named ''system information variables'' (Novell / Caldera terminology)<ref name="Caldera_1998_USER"/> or ''internal variables'' (JP Software terminology),<ref name="4DOS_8.00_HELP"/> 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 (DOS command)|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]] ("<code>_</code>") by 4DOS etc. by convention (f.e. <code>[[#%_SECOND%|%_SECOND%]]</code>),<ref name="4DOS_8.00_HELP"/> they are not under DR-DOS <code>COMMAND.COM</code> (f.e. <code>[[#%OS_VERSION%|%OS_VERSION%]]</code>). {{anchor|Variable function}}In addition, 4DOS, 4OS2, 4NT, and Take Command also support so called ''variable functions'',<ref name="4DOS_8.00_HELP"/> including user-definable ones. They work just like ''internal variables'', but can take optional parameters (f.e. <code>%@EVAL[]%</code>) and may even change the system status depending on their function. ''System information variables'' supported by DR-DOS <code>COMMAND.COM</code>: ;{{anchor|%AM_PM%}}<code>%AM_PM%</code>: This pseudo-variable returns the ante- or post-midday status of the current time. The returned string depends on the locale-specific version of DR-DOS, f.e. "<code>am</code>" or "<code>pm</code>" in the English version. It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. ;{{anchor|%DAY%|DAY%}}<!-- DAY% just to work-around a parsing problem with the link found in the %_DAY% entry below --><code>%DAY%</code>: This pseudo-variable returns the days of the current date in a 2-digit format with leading zeros, f.e. "<code>01</code>".."<code>31</code>". See also the similar pseudo-variable <code>[[#%_DAY%|%_DAY%]]</code>. It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. ;{{anchor|%DAY_OF_WEEK%}}<code>%DAY_OF_WEEK%</code>: This pseudo-variable returns the day name of the week in a 3-character format. The returned string depends on the locale-specific version of DR-DOS, f.e. "<code>Sun</code>", "<code>Mon</code>", "<code>Tue</code>", "<code>Wed</code>", "<code>Thu</code>", "<code>Fri</code>", or "<code>Sat</code>" in the English version. It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. ;{{anchor|%ERRORLEVEL%}}<code>%ERRORLEVEL%</code>: In <code>COMMAND.COM</code> of DR-DOS 7.02 and higher, this pseudo-variable returns the last error level returned by an external program or the <code>[[RETURN (DOS command)|RETURN]]</code> command, f.e. "<code>0</code>".."<code>255</code>".<ref name="Paul_1997_BATTIPS"/><ref name="FD_2003_Errorlevel"/> See also the identically named pseudo-variable <code>[[#ERRORLEVEL|%ERRORLEVEL%]]</code> under Windows and the <code>[[IF ERRORLEVEL (DOS command)|IF ERRORLEVEL]]</code> conditional command. ;{{anchor|%ERRORLVL%}}<code>%ERRORLVL%</code>: In DR-DOS 7.02 and higher, this pseudo-variable returns the last error level in a 3-digit format with leading zeros, f.e. "<code>000</code>".."<code>255</code>".<ref name="Paul_1997_BATTIPS"/><ref name="FD_2003_Errorlevel"/> Under [[Multiuser DOS]], this is a true environment variable automatically updated by the shell to the return code of exiting programs.<ref name="CCI_1997_HELP"/> See also the related pseudo-variable <code>[[#%ERRORLEVEL%|%ERRORLEVEL%]]</code> under DR-DOS and the <code>[[IF ERRORLEVEL (DOS command)|IF ERRORLEVEL]]</code> command. ;{{anchor|%GREETING_TIME%}}<code>%GREETING_TIME%</code>: This pseudo-variable returns the 3-level day greeting time. The returned string depends on the locale-specific version of DR-DOS, f.e. "<code>morning</code>", "<code>afternoon</code>", or "<code>evening</code>" in the English version. It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. ;{{anchor|%HOUR%}}<code>%HOUR%</code>: This pseudo-variable returns the hours of the current time in 12-hour format without leading zeros, f.e. "<code>1</code>".."<code>12</code>". It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. ;{{anchor|%HOUR24%}}<code>%HOUR24%</code>: This pseudo-variable returns the hours of the current time in 24-hour format in a 2-digit format with leading zeros, f.e. "<code>00</code>".."<code>23</code>". It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. See also the similar pseudo-variable <code>[[#%_HOUR%|%_HOUR%]]</code>. ;{{anchor|%MINUTE%}}<code>%MINUTE%</code>: This pseudo-variable returns the minutes of the current time in a 2-digit format with leading zeros, f.e "<code>00</code>".."<code>59</code>". It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. See also the similar pseudo-variable <code>[[#%_MINUTE%|%_MINUTE%]]</code>. ;{{anchor|%MONTH%}}<code>%MONTH%</code>: This pseudo-variable returns the months of the current date in a 2-digit format with leading zeros, f.e. "<code>01</code>".."<code>12</code>". It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. See also the similar pseudo-variable <code>[[#%_MONTH%|%_MONTH%]]</code>. ;{{anchor|%MONTH_NAME%}}<code>%MONTH_NAME%</code>: This pseudo-variable returns the month name of the current date. The returned string depends on the locale-specific version of DR-DOS, f.e. "<code>January</code>", "<code>February</code>", "<code>March</code>", "<code>April</code>", "<code>May</code>", "<code>June</code>", "<code>July</code>", "<code>August</code>", "<code>September</code>", "<code>October</code>", or "<code>December</code>" in the English version. It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. ;{{anchor|%NDAY_OF_WEEK%}}<code>%NDAY_OF_WEEK%</code>: This pseudo-variable returns the number of day of the current week, f.e. "<code>1</code>".."<code>7</code>" (with "<code>1</code>" for Sunday). It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. ;{{anchor|%OS_VERSION%}}<code>%OS_VERSION%</code>: This pseudo-variable returns the version of the operating system depending on the current setting of the environment variable <code>[[#%VER%|%VER%]]</code>. If <code>%VER%</code> is not defined, <code>%OS_VERSION%</code> returns "<code>off</code>". It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts, which may return versions also for non-DR-DOS versions of DOS. ;{{anchor|%SECOND%}}<code>%SECOND%</code>: This pseudo-variable returns the seconds of the current time in a 2-digit format with leading zeros, f.e. "<code>00</code>".."<code>59</code>". It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. See also the similar pseudo-variable <code>[[#%_SECOND%|%_SECOND%]]</code>. ;{{anchor|%SHORT_YEAR%}}<code>%SHORT_YEAR%</code>: This pseudo-variable returns the year of the current date in a 2-digit format with leading zeros, f.e. "<code>93</code>".."<code>99</code>", "<code>00</code>".."<code>92</code>". It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. ;{{anchor|%YEAR%|%_YEAR%}}<code>%YEAR%</code> and <code>%_YEAR%</code>: Supported since [[Novell DOS 7]], the <code>%YEAR%</code> pseudo-variable returns the year of the current date in a 4-digit format, f.e. "<code>1980</code>".."<code>2099</code>". It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. DR-DOS 7.02 and higher added <code>%_YEAR%</code> for compatibility with [[4DOS]], returning the same value.<ref name="4DOS_8.00_HELP"/> ;{{anchor|%/%}}<code>%/%</code>: In <code>COMMAND.COM</code> of DR-DOS 7.02 and higher, this pseudo-variable returns the current [[SwitChar]] setting of the system, either "<code>/</code>" (DOS style) or "<code>-</code>" (Unix style)<!-- "[" not officially supported by %/% -->.<ref name="Caldera_1998_DELTREE101"/><ref name="Caldera_1998_NEW703"/> See also the related <code>CONFIG.SYS</code> directive [[SWITCHAR (CONFIG.SYS directive)|SWITCHAR]] and the environment variable <code>[[#%SWITCHAR%|%SWITCHAR%]]</code>. ;{{anchor|%_CODEPAGE%}}<code>%_CODEPAGE%</code>: This pseudo-variable returns the systems' current [[code page]] ("<code>1</code>".."<code>65533</code>"<!-- 0, 65534 and 65535 are reserved values -->), f.e. "<code>[[Codepage 437|437]]</code>", "<code>[[Codepage 850|850]]</code>", "<code>[[Codepage 858|858]]</code>". This variable was originally introduced by [[4DOS]],<ref name="4DOS_8.00_HELP"/> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the <code>[[CHCP (DOS command)|CHCP]]</code> command. ;{{anchor|%_COLUMNS%}}<code>%_COLUMNS%</code>: This pseudo-variable returns the current number of screen columns depending on the display mode, f.e. "<code>40</code>", "<code>80</code>", "<code>132</code>", etc. This variable was originally introduced by [[4DOS]],<ref name="4DOS_8.00_HELP"/> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also a similar environment variable <code>[[#%$WIDTH%|%$WIDTH%]]</code> under DOS Plus. ;{{anchor|%_COUNTRY%}}<code>%_COUNTRY%</code>: This pseudo-variable returns the systems' current [[List of country calling codes|country code]] ("<code>1</code>".."<code>65534</code>"<!-- 0 and 65535 are reserved values -->), f.e. "<code>1</code>" for USA, "<code>44</code>" for UK, "<code>49</code>" for Germany, "<code>20049</code>" with [[ISO 8601]], "<code>21049</code>"<!-- with Euro support and <code>22049</code>" --> with ISO 8601 and [[Euro currency|Euro]] support.<ref name="Caldera_1998_NEW703"/><ref name="Paul_2001_COUNTRY"/> This variable was originally introduced by [[4DOS]],<ref name="4DOS_8.00_HELP"/> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the <code>CONFIG.SYS</code> directive <code>[[COUNTRY (CONFIG.SYS directive)|COUNTRY]]</code>. ;{{anchor|%_DAY%}}<code>%_DAY%</code>: This pseudo-variable returns the days of the current date without leading zeros, f.e. "<code>1</code>".."<code>31</code>". This variable was originally introduced by [[4DOS]],<ref name="4DOS_8.00_HELP"/> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the similar pseudo-variable <code><!-- DAY% (instead of the correct %DAY% just to work-around a parsing problem with the link -->[[#DAY%|%DAY%]]</code>. ;{{anchor|%_HOUR%}}<code>%_HOUR%</code>: This pseudo-variable returns the hours of the current time in 24-hour format without leading zeros, f.e. "<code>0</code>".."<code>23</code>". This variable was originally introduced by [[4DOS]],<ref name="4DOS_8.00_HELP"/> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the similar pseudo-variable <code>[[#%HOUR24%|%HOUR24%]]</code>. ;{{anchor|%_MINUTE%}}<code>%_MINUTE%</code>: This pseudo-variable returns the minutes of the current time without leading zeros, f.e "<code>0</code>".."<code>59</code>". This variable was originally introduced by [[4DOS]],<ref name="4DOS_8.00_HELP"/> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the similar pseudo-variable <code>[[#%MINUTE%|%MINUTE%]]</code>. ;{{anchor|%_MONTH%}}<code>%_MONTH%</code>: This pseudo-variable returns the months of the current date without leading zeros, f.e. "<code>1</code>".."<code>12</code>". This variable was originally introduced by [[4DOS]],<ref name="4DOS_8.00_HELP"/> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the similar pseudo-variable <code>[[#%MONTH%|%MONTH%]]</code>. ;{{anchor|%_ROWS%}}<code>%_ROWS%</code>: This pseudo-variable returns the current number of screen rows depending on the display mode, f.e. "<code>25</code>", "<code>43</code>", "<code>50</code>", etc. This variable was originally introduced by [[4DOS]],<ref name="4DOS_8.00_HELP"/> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See a similar environment variable <code>[[#%$LENGTH%|%$LENGTH%]]</code> under DOS Plus. ;{{anchor|%_SECOND%}}<code>%_SECOND%</code>: This pseudo-variable returns the seconds of the current time without leading zeros, f.e. "<code>0</code>".."<code>59</code>". This variable was originally introduced by [[4DOS]],<ref name="4DOS_8.00_HELP"/> but also became available with <code>COMMAND.COM</code> since DR-DOS 7.02. See also the similar pseudo-variable <code>[[#%SECOND%|%SECOND%]]</code>. ''System information variables'' supported by DR-DOS <code>COMMAND.COM</code> with networking loaded: ;{{anchor|%LOGIN_NAME%}}<code>%LOGIN_NAME%</code>: This pseudo-variable returns the user name. This always worked with <code>[[NETX]]</code>, but it will also work with [[Personal NetWare]]'s [[Open Data-Link Interface|ODI]]/[[Virtual Loadable Module|VLM]]<!-- since Novell DOS 7 Update 14 --> if the current drive is a PNW-mapped drive (otherwise an empty string is returned). See also the similarly named environment variable <code>[[#%LOGINNAME%|%LOGINNAME%]]</code>. ;{{anchor|%P_STATION%}}<code>%P_STATION%</code>: This pseudo-variable returns the physical station number in a format "<code>????????????</code>". 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. ;{{anchor|%STATION%}}<code>%STATION%</code>: This pseudo-variable returns the logical station number starting with "<code>1</code>" 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. ;{{anchor|%FULL_NAME%}}<code>%FULL_NAME%</code>: This pseudo-variable returns the full name of the logged in user, if available. It resembles an identically named ''identifier variable'' in [[Novell NetWare]] login scripts. See also the related pseudo-variable <code>[[#%LOGIN_NAME%|%LOGIN_NAME%]]</code>. ==={{anchor|WIN-PSEUDOENV}}Windows === ''Dynamic environment variables'' (also named ''internal variables'' or ''system information variables'' under DOS) are pseudo-environment variables supported by <code>[[CMD (Windows)|CMD.EXE]]</code> 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 by <code>SET</code> nor do they exist for external programs to read. They are not case-sensitive. Indirectly, they are also supported under Windows' <code>COMMAND.COM</code>, which has been modified to internally call <code>CMD.EXE</code> to execute the commands.<!-- see ECHO %CMDCMDLINE% under COMMAND.COM --> ;{{anchor|CD}}<code>%CD%</code>: This pseudo-variable expands to the current directory equivalent to the output of the command <code>[[cd (command)|CD]]</code> when called without arguments. While a long filename can be returned under <code>CMD.EXE</code> depending on the current directory, the fact that the current directory will always be in [[8.3 filename|8.3]] format under <code>COMMAND.COM</code> will cause it to return a short filename under <code>COMMAND.COM</code>, even when <code>COMMAND</code> internally calls <code>CMD</code>. ;{{anchor|CMDCMDLINE}}<code>%CMDCMDLINE%</code>: This pseudo-variable expands to the original startup parameters of <code>[[CMD.EXE]]</code>, f.e. "<code>C:\Windows\system32\cmd.exe</code>". Under Windows' <code>COMMAND.COM</code>, this may return something like "<code>C:\Windows\system32\cmd.exe /c ...</code>" due to the fact that <code>COMMAND.COM</code> calls <code>CMD.EXE</code> internally. ;{{anchor|CMDEXTVERSION}}<code>%CMDEXTVERSION%</code>: This pseudo-variable expands to the version of the command-line extensions of <code>[[CMD.EXE]]</code>, if enabled (e.g. "<code>1</code>" under [[Windows NT]], "<code>2</code>" under [[Windows 2000]] and [[Windows XP]]). ;{{anchor|DATE}}<code>%DATE%</code>: This pseudo-variable expands to the current date. The date is displayed according to the current user's [[Calendar date|date format]] preferences. ;{{anchor|ERRORLEVEL}}<code>%ERRORLEVEL%</code>: This pseudo-variable expands to the last set error level, a value between "<code>0</code>" and "<code>255</code>" (without leading zeros).<ref name="Paul_1997_BATTIPS"/><ref name="Allen_2005"/><ref name="FD_2003_Errorlevel"/> External commands and some internal commands set error levels upon execution. See also the identically named pseudo-variable <code>[[#%ERRORLEVEL%|%ERRORLEVEL%]]</code> under DR-DOS and the <code>[[IF ERRORLEVEL (Windows command)|IF ERRORLEVEL]]</code> command. ;{{anchor|HIGHESTNUMANODENUMBER}}<code>%HIGHESTNUMANODENUMBER%</code>: This pseudo-variable returns the number of the highest [[Non-uniform memory access|NUMA]] node. ;{{anchor|RANDOM}}<code>%RANDOM%</code>: This pseudo-variable returns a random number between "<code>0</code>" and "<code>32767</code>". ;{{anchor|TIME}}<code>%TIME%</code>: This pseudo-variable returns the current time. The time is displayed according to the current user's time format preferences. If the <code>%TIME%</code> and <code>[[#DATE|%DATE%]]</code> 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. ===Other shells=== Unix-like shells have similar dynamically generated variables, bash's <code>$RANDOM</code> being a well-known example. However, since these shells have a concept of local variables, they are described as special local variables instead.<ref name="GNU_BASH"/>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)