Disk Operating System (DOS)

How to create, display, and use DOS environmental variables from batch files and the command line. Includes PATH, PROMPT, and PROMPT meta-strings as well as a technique to expand the DOS environment using SHELL.

The DOS Environment

Definition

The DOS environment is a reserved segment of primary memory called the Master Environment Block. The environment is used to store system information in the form of environmental variables, or environmental strings.

Environmental variables are available to the operating system, batch files, and application programs and are used to modify the behavior of DOS commands and application programs, or to provide them with additional information.

Displaying Environmental Variables

To display the contents of the DOS environment, type SET at the DOS prompt and hit the Enter key.

A copy of the environment can be placed in a text file by using redirection:

SET > EVAR.TXT

Creating or Modifying Environmental Variables

From the command line, the command used to create a new environmental variable, or to change the value for an existing one, is:

SET VARNAME=textString

From within a batch file, use the form:

VARNAME=textString

Environmental Variable Examples

PATH

When DOS is given a command and it cannot find that command in memory or the current directory (see How DOS finds commands), it searches the environment for a variable called PATH.

If it finds that variable it will look for the command in all of the places which are listed after the PATH variable, each one separated from the next by a semicolon.

Example:

PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;D:\TOOLS\MYEDITOR;D:\UTILS

To append a new location to the existing PATH from the command line, use this form:

SET PATH=%PATH%;D:\BIN

PROMPT

The DOS prompt is the operating system's signal that it is ready for a command. The default DOS prompt is the letter of the current drive only. Use the SET PATH command in AUTOEXEC.BAT to modify the DOS prompt to provide additional information.

The following meta-strings can be used in addition to regular character strings:

Meta Symbol Translates to
$a ampersand
$b | (pipe)
$c ( (left parenthesis)
$d date
$e escape char
$f ) (right parenthesis)
$g > (greater than symbol)
$h backspace
$l < (less than symbol)
$n current drive
$p Current drive/directory
$q = (equal sign)
$s (space)
$t time
$v version
$_ Begin new line on screen
$$ $ (dollar sign)

Example:

SET PROMPT=Today is $D $_The time is $T$_$_$P$G

The prompt displayed by DOS as a result would look like this:

Today is 11/06/2004 The time is 15:31:55 D:\UTIL>

COMSPEC (command.com specification)

COMMAND.COM is loaded into different parts of high and low memory. Those parts which control internal commands and batch files are not needed when an application is running and the application may overwrite them.

When the application terminates and control is returned to DOS, however, those parts of DOS must be re-loaded into memory from disk. This takes a considerable amount of time on a floppy system.

To speed up the process, create a 40K RAMDISK, copy COMMAND.COM there, and use the COMSPEC command to specify where DOS should look for COMMAND.COM on disk. This is usually accomplished within AUTOEXEC.BAT:

(Create RAMDISK drive C:) COPY A:COMMAND.COM C: SET COMPSPEC=C:\COMMAND.COM

Provide information to programs and batch files

The DOS environment can be used as a general purpose memory pool accessible by all programs and batch files.

Customizing a text editor (ED=PC-Write):

SET ED=(ALT G).XT:2

Pointing a database program to its data files (AE=AE:Address):

SET AE=D:\DATA\AE

SHELL

The default shell for DOS is COMMAND.COM. However, the SHELL command allows us to specify a different (3rd party) command processor to be used.

SHELL=COMPLUS.EXE

Expanding the environment

The default size of the DOS environment is 160 characters. Often this is insufficient to accommodate the total environmental variables in use. To expand the environmental space:

Under DOS 3.0 and 3.1:

SHELL C:\COMMAND.COM /e:60 /p Where 60 = 60 16 byte memory paragraphs: 60x16, or 960bytes

Under DOS 3.2 and up:

SHELL = COMMAND.COM /e:x /p Where x= 160 to 32,768 bytes

(The /p switch instructs COMMAND.COM to run AUTOEXEC.BAT)


Bruce Miller, 2004, 2014