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.
PROMPT environment variableThe 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:
DPATH environment variableThe 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.
PATH environment variableThe 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.
PATHEXT environment variableThe 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.
TZ environment variableThe 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:
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.
COMSPEC environment variableNote: 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.
OS2_SHELL environment variablePrograms 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.
DIR_COLOURS environment variableThe 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
:D bright cyan on black
:H bri bla bla
*.{bat,btm,cmd} bri red bla
"* *" yel bri blu
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:
Example 1: A bug in Watcom C/C++'s runtime library to do with the way that it constructs the command area before calling DosExecPgm() to run any command, causes programs compiled with Watcom C/C++ (such as Watcom's own toolset, including WMAKE) to pass extra garbage in the command area when they spawn child processes (e.g. when WMAKE runs commands). To avoid this bug, one sets the CMD_CMD_INIT environment variable (assuming that CMD is the command interpreter front end that one is using) to include the /ONETAIL option, so that whatever extra garbage Watcom C/C++'s runtime library passes in the command area will be ignored.
Example 2: The quirky behaviour of (amongst others) the COPY command built in to the 16-bit CMD supplied with IBM OS/2 can be duplicated by placing the /OLDSRCDIR and /OLDDESTDIR options in the CMD_COPY_INIT environment variable.
Example:
To emulate the behaviour of JP Software's 4OS2 in
TEXTCMD,
set the CMD_TEXTCMD_INIT environment variable to the value
"4START", which will cause the command "4START" (which must be in the
PATH, of course) to be invoked by the command interpreter before it
executes any other command line.