Environment variables

The PROMPT, DPATH, PATH, PATHEXT, TZ, COMSPEC, OS2_SHELL, and DIR_COLOURS environment variables and the various CMD_xxxx_INIT environment variables control various parts of the operation of the 32-bit Command Interpreter and of the various external commands.

The PROMPT environment variable

The PROMPT environment variable controls what the command interpreter displays as the prompt for interactive input. The contents of the variable are displayed to standard output with the following substitutions made:

$$
The $ (dollar) character
$A or $a
The & (ampersand) character
$B or $b
The | (bar) character
$C or $c
The ( character
$D
The date in standard ISO 8601 form
$d
The date in your country's local form
$E or $e
The escape character (ASCII 27)
$F or $f
The ) character
$G or $g
The > (greater than) character
$H or $h
The backspace character (ASCII 8)
$I or $i
The help banner
$L or $l
The < (less than) character
$M
The time in HH:MM form
$m
The time in HH:MM:SS XM form (12-hour)
$N or $n
The drive letter of the current drive
$P or $p
The current directory on the current drive
$Q or $q
The = (equals) character
$R or $r
The return value of the most recent command
$S or $s
The space character (ASCII 32)
$T
The time in standard ISO 8601 form
$t
The time in your country's local form
$U
The timezone as an offset from UTC
$u
The timezone name
$V or $v
The command interpreter and operating system version
$Xd or $xd
The current directory on the drive 'd'
$_
A carriage return and line-feed

The DPATH environment variable

The DPATH environment variable comprises a list of directory names separated by semi-colons. It is a standard environment variable used by OS/2 programs when they are searching for message text files, which contain the text of the various prompt, informational, help, and error text messages (thereby allowing commands to be customised for different languages without needing to modify the commands themselves). Each directory on the list is searched in turn for the file.

If the DPATH environment variable does not exist, the default behaviour is determined by the operating system. IBM OS/2, if DPATH does not exist, searches only the current directory.

The PATH environment variable

The PATH environment variable comprises a list of directory names separated by semi-colons. When searching for external command files, the command interpreter scans each directory in the list in turn.

The behaviour is slightly different to that of the 16-bit CMD supplied with IBM OS/2, in that no implicit search is performed in the current directory before the directories listed in PATH are searched. To search the current directory, it must be explicitly included in the list. This is so that one is able to control where in the sequence the current directory is searched. To duplicate the behaviour of the 16-bit CMD supplied with IBM OS/2, simply list the current directory first. The simplest way to do this is to add an empty string and a semi-colon to the start of PATH:

set PATH=;C:\OS2

To allow for directory names that themselves contain semi-colons, directory names may be enclosed in quotation marks. To include literal quotation marks in directory names, they must be preceded by a backslash in order to prevent their having any special meaning.

If the PATH environment variable does not exist, the default is to use an empty string. An empty string causes only the current directory to be searched.

The PATHEXT environment variable

The PATHEXT environment variable comprises a list of filename extensions separated by semi-colons. When searching for external command files, each extension in turn is appended to the command name to form a filename. If a file of that name exists, the command interpreter attempts to execute it as an external command.

If the PATHEXT environment variable does not exist, the default extension list is ";.com;.exe;.bat;.cmd". This is the same as the extension list that is hard-coded into the 16-bit CMD supplied with IBM OS/2. It specifies to search first for the filename exactly as given (because the first extension in the list, before the first semi-colon, is an empty string), and then with the extensions COM, EXE, BAT, and CMD in order.

The TZ environment variable

The TZ environment variable determines the names for standard and daylight savings time in the current timezone, the offsets from UTC for each, and the rules to apply to determine when each is in effect.

Since this information is stored in an environment variable, one can potentially run multiple command interpreter processes all with different TZ environment variables on the same machine, allowing multiple timezones to be used simultaneously.

The contents of the TZ environment variable are in the standard POSIX 1003.1 (ISO/IEC 9445-1:1990) format:

  sss[hh[:mm]]ddd[hh[:mm]][,start[/hh[:mm[:ss]]][,end[/hh[:mm[:ss]]]]]

The first part of the TZ environment variable (sss[hh[:mm]]ddd[hh[:mm]]) determines the names for standard and daylight savings time, and their offset from UTC in hours and (optionally) minutes west of of the Prime Meridian (i.e. the amount to subtract from UTC to obtain local standard/daylight savings time). If no offset is given for daylight savings time, the default is for it to be exactly one hour east of standard time.

The second part ([,start[/hh[:mm[:ss]]][,end[/hh[:mm[:ss]]]]]) gives rules for calculating the exact time for the start and end of daylight savings time, specifying the day of the year, and optionally the hour, minute, and second (in standard time), at which daylight savings time starts and ends. The "start" and "end" portions specify the day of the year, and can be in one of three forms:

Mm.w.d
The letter 'M' followed by three numbers, separated by dots, indicates the first day of week 'w' of month 'm', where weeks are considered to start on day 'd' (Sunday = 0).
Jn
The letter 'J' followed by a number, indicating the Nth day of the year (1-365), where February the 29th has no number.
n
A number, indicating the Nth day of the year (1-366).

If the "start" day is earlier in the year than the "end" day, as it will be for the Northern Hemisphere, daylight savings time will apply between those days, and standard time otherwise. Otherwise, standard time will apply between the two days, and daylight savings time otherwise.

The "time" portion specifies the hour, minute, and second, standard time, at which the change occurs. If it is omitted, the default is 02:00:00.

The default start and end rules mandated by ISO/IEC 9445-1:1990, if none are supplied, are ",M4.1.0/02:00:00,M10.5.0/02:00:00", which is the rule that has applied in the United States of America since 1987. ("First Sunday in April, at 02:00:00 standard time, and last Sunday in October, at 02:00:00 standard time."). European users should note that this default rule is incorrect for many EU countries. This rule is also incorrect for all countries in the Southern Hemisphere.

U.K. users should note that this scheme cannot encode the daylight savings time rules that are laid out in the Summer Time Act 1972. Luckily, the U.K. is part of the EU, and EU harmonisation directives override the Summer Time Act each year with simpler daylight savings time rules that can be encoded.

Examples

GMT0BST1,M3.5.0/01:00:00,M10.5.0/01:00:00
The full string for the U.K. including the correct rule for the years 1998 to 2001 (as specified in Statutory Instrument 1997/2982).
GMT0BST,M3.5/1,M10.5/1
A shorter, but functionally identical, form of the above.
CET-1CEST
The string for Germany and other central European countries. The DST rule for the years 1998 to 2001 just happens to be identical to the POSIX default, and so can be omitted.
EST-10EDT,M10.5.0,M3.5.0
Australian Eastern Standard/Daylight time.
CST-9:30CDT,M10.5.0,M3.5.0
Australian Central Standard/Daylight time.
EST5EDT
U.S. Eastern Standard/Daylight time.
PST8PDT
U.S. Pacific Standard/Daylight time.
NST3:30NDT1:30
Newfoundland Standard/Daylight time.

The COMSPEC environment variable

Note: JP Software's 4OS2, when it first starts up, before it even parses its command line, automatically modifies the COMSPEC environment variable in its environment so that its value is the name of the command interpreter executable file. It also modifies the COMSPEC environment variable when a program named "CMD" is run. This behaviour is not documented, and is not mimicked by the 32-bit Command Interpreter. The value of COMSPEC when the 32-bit Command Interpreter first starts is whatever was inherited from its parent process, and that only changes when explicitly modified by the SET command.

Programs use the value of the COMSPEC environment variable as the filename of the program to execute when they need to invoke a non-interactive command interpreter. (For interactive command interpreters, they should use the OS2_SHELL environment variable.)

The 32-bit Command Interpreter itself uses the value of the COMSPEC environment variable when it is invoking a child process to execute the left-hand side of a command pipeline. Modifying the COMSPEC environment variable to not be the name of a valid command interpreter will thus cause problems when executing command pipelines.

The DETACH command and the START command also use the value of the COMSPEC environment variable. Modifying the COMSPEC environment variable to not be the name of a valid command interpreter will thus cause problems when using these commands.

The OS2_SHELL environment variable

Programs use the value of the OS2_SHELL environment variable as the filename of the program to execute when they need to invoke an interactive command interpreter. (For non-interactive command interpreters, they should use the COMSPEC environment variable.)

The DETACH command and the START command also use the value of the OS2_SHELL environment variable. Modifying the OS2_SHELL environment variable to not be the name of a valid command interpreter will thus cause problems when using these commands.

The DIR_COLOURS environment variable

The DIR_COLOURS environment variable comprises a list of colouring rules separated by semi-colons. A colouring rule specifies either an attribute mask or a search wildcard specification, followed by a colour specification giving the colour to use when a file's attribute matches the mask or its base name matches the wildcard.

Attribute masks are indicated by a leading colon (':') character. Because they are otherwise terminated by the first white space found, wildcards must be quoted if they need to contain white space characters.

Example:

set DIR_COLOURS=:D bri cya bla;*.{bat,btm,cmd} bri red bla;*.{exe,com} bri gre bla;*.{zip,zoo,arc,arj,lzh,rar} bri yel bla;*.{drv,dll,mak} mag bla

Example colouring rules

:D bright cyan on black
Display directories in bright cyan on black.
:H bri bla bla
Display hidden files in bright black (i.e. grey) on black.
*.{bat,btm,cmd} bri red bla
Display command scripts in bright red on black.
"* *" yel bri blu
Display filenames containing at least one space character in yellow on bright blue.

The CMD_xxxx_INIT environment variables

All of the command interpreter front ends, and the COPY, DEL, DIR, MORESTD, MOVE, RENAME, TYPE, and ZDIR commands, recognise environment variables with names of the form CMD_XXXX_INIT, where XXXX is the name of the command (or front end). If they inherit such an environment variable when they start, they process the value of that variable as if it were a command tail, before they process any actual command tail that is passed to them.

Two of the uses for this mechanism are:


The 32-bit Command Interpreter is © Copyright Jonathan de Boyne Pollard. "Moral" rights are asserted.