In this appendix
The environment is a small area in memory that DOS sets aside for storing text variables. Normally, you set the size of the master environment area with a SHELL =
statement in your CONFIG.SYS
file. The default size of the environment is 256 bytes, but you almost certainly want to increase this size as you begin to use environment variables to automate your daily tasks.
Each variable in the environment consists of two parts: the name of the variable, which DOS stores in uppercase characters, and the contents of the variable, which is the text associated with the variable. Normally, you view, create, and replace environment variables by using the SET
command. The PATH
and PROMPT
commands store their settings in the environment. MS-DOS automatically creates certain environment variables, such as COMSPEC
and CONFIG
, when you start up your computer.
Whenever DOS loads a program into memory, it makes a copy of the current environment and passes this copy to the program. This copy is only big enough to include the variables currently defined in the environment, rounded up to an even multiple of 16 bytes. Although this use of memory is efficient, it is inconvenient for people who normally operate from a shell program such as DOS Shell, Norton Commander, or XTree because not much environment space is available, no matter how large an environment area you set aside. If you get an Out of environment space
message while you are running a shell program, quit the shell and try the operation again. If you still receive an error message, you must increase the size of the master environment by using the SHELL=
statement in your CONFIG.SYS
file.
The following sections list the standard environment variables used by MS-DOS. Also noted is the version of DOS in which the variable first appeared, along with the creator of the variable. An MS-DOS label indicates that this variable is created automatically when your computer starts up. A User label indicates that you must create it by using the SET
command or, for certain variables, the PATH
, PROMPT
, or APPEND
command. A Windows label indicates that the environment variable is created by Microsoft Windows.
The APPEND
environment variable is created by DOS if you specify the /E
parameter when loading APPEND
into memory. With the /E
parameter, APPEND
stores the appended directory search path in the environment instead of internally.
This variable is stored much like the PATH
variable. It is a list of subdirectories to be searched, separated by semicolons. If the APPEND
environment variable is created with the SET
command, it might appear like this:
SET APPEND=C:DOS;C:WS
When you instruct APPEND
to store the appended directory search path in the environment, you can change or replace the search path by using the SET
command as well as the APPEND
command.
Note that APPEND/E
does not work if you are launching programs that must search the appended directory search path from a shell program such as DOS Shell, Norton Commander, or XTree. In such cases, APPEND
must store the appended directory search path internally.
The COMSPEC
variable points to the active copy of the command interpreter shell loaded with the SHELL=
command in your CONFIG.SYS
file. All of COMMAND.COM
isn't in memory all the time; when parts of it must be reloaded, the COMSPEC
variable is used to find the COMMAND.COM
file on disk.
In the following SHELL=
command, COMMAND.COM
sets the COMSPEC
variable using the C:DOS
parameter that follows the command interpreter's name:
SHELL=C:DOSCOMMAND.COM C:DOS /E:512 /P
DOS executes the SHELL=
command at the end of CONFIG.SYS
processing. When it does, COMMAND.COM
sets the COMSPEC
variable in the environment as if it had executed SET COMSPEC=C:DOSCOMMAND.COM
. (Note that COMMAND.COM
doesn't actually use the SET
command.)
Many programs search the environment for the COMSPEC
variable when they must locate COMMAND.COM
. If you have trouble shelling to a DOS prompt from one of your application programs, check the COMSPEC
environment variable and make sure that it's pointing to a valid copy of COMMAND.COM
.
When MS-DOS processes a startup menu in CONFIG.SYS
, it defines the CONFIG
environment variable, setting it equal to the block name of the menu item you selected. You can use the CONFIG
environment variable with GOTO
and IF
in your AUTOEXEC.BAT
file to continue making choices based on the configuration chosen in the startup menu.
For example, assume that your CONFIG.SYS
file includes the following startup menu:
[MENU] MENUITEM=WIN, Configure for Windows (default) MENUITEM=DOS, Configure for MS-DOS MENUITEM=MAINT, Configure for file & disk maintenance MENUDEFAULT=WIN, 10
The CONFIG
environment variable is set equal to WIN
, DOS
, or MAINT
, depending on which configuration you select when your computer displays the startup menu. In your AUTOEXEC.BAT
file, you can check this value and process different commands for each configuration. For example, you might set up separate sections for each startup configuration and label them with the block names you used in your CONFIG.SYS
file, which in this case are :WIN
, :DOS
, and :MAINT
. (For more information on block names, see the [blockname]
entry in Appendix F,“Command Reference.”) Then, a simple GOTO
statement such as the following might be all you need to jump to the correct section of your AUTOEXEC.BAT
file:
GOTO %CONFIG%
A slightly safer method is to check each value with an IF
statement and report an error if an unexpected value for CONFIG
is encountered:
IF %CONFIG%x==WINx GOTO WIN IF %CONFIG%x==DOSx GOTO DOS IF %CONFIG%x==MAINTx GOTO MAINT GOTO ERROR
The use of x
prevents the generation of an error message if the CONFIG
environment variable is null or undefined. When you use an IF
comparison, always include a character (any character will do) that prevents one side of the equation from being empty.
Starting with MS-DOS 6.2, COPY
, MOVE
, and XCOPY
all prompt for confirmation before overwriting a file. Because this behavior might wreak havoc with your old batch files, this behavior is the default only when these commands are run from the command line. If COPY
, MOVE
, or XCOPY
is run from a batch file, it overwrites files without warning, which is its behavior in previous versions of DOS.
You can change the new default behavior by defining an environment variable named COPYCMD
. To force COPY
, MOVE
, and XCOPY
to prompt you before overwriting a file in all cases, even from a batch file, add the following line to your AUTOEXEC.BAT
file:
SET COPYCMD=/-Y
To prevent COPY
, MOVE
, and XCOPY
from prompting before overwriting a file, add the following line to your AUTOEXEC.BAT
file:
SET COPYCMD=/Y
The DIRCMD
environment variable customizes the default options the DIR
command uses. When you run the DIR
command, the contents of the DIRCMD
environment variable—if it exists—are added invisibly to what you type on the command line.
Suppose that you prefer filenames in lowercase letters, sorted by directories and then sorted by date and time. You also want the screen to pause after each page of files is displayed. You can define the DIRCMD
variable in your AUTOEXEC.BAT
file as follows:
SET DIRCMD=/L /O:GD /P
Now you don't have to enter those options every time you want to use them. To override these options, specify the switch with a hyphen added before the letter. For example, to turn off the pause option in your customized DIR
command, enter the following command:
DIR /-P
Note that overriding options this way is temporary and changes only the behavior of the command in which the override switch appears.
The MSDOSDATA
environment variable defines where certain DOS utility programs look for their data files. Defining this variable can make it easier to keep programs and data separate on your hard disk. Defining the variable can make it easier also to run these utility programs from a network using individual configuration files.
The most convenient place to define the MSDOSDATA
variable is in your AUTOEXEC.BAT
file with a SET
command. Here's an example:
SET MSDOSDATA=C:DOSDATA
This line sets MSDOSDATA
to point to the C:DOSDATA
subdirectory on your hard drive. Note that this subdirectory has to exist first; the SET
command does not create it for you.
Table B.1 provides a list of the MS-DOS programs that create data files as well as the locations where the programs look for the data files.
Table B.1. Data File Search Paths
Program | Data File | Primary Location | Secondary Location |
---|---|---|---|
DBLSPACE
|
DBLSPACE.INF DBLSPACE.INI | Program directory Program directory | |
DOSSHELL
| DOSSHELL.INI
| DOSSHELL
| Program directory
|
MEMMAKER
|
MEMMAKER.INI MEMMAKER.STS | Program directory Program directory | |
MSAV
|
CHKLST.MS MSAV.INI | All directories MSDOSDATA
| Program directory |
MSBACKUP
|
MSBACKUP.INI *.DIF *.FUL *.INC *.SET *.SLT |
MSDOSDATA MSDOSDATA MSDOSDATA MSDOSDATA MSDOSDATA MSDOSDATA | Program directory Program directory Program directory Program directory Program directory Program directory |
MWAV
| MWAV.INI
| MSDOSDATA
| Program directory
|
MWBACKUP
|
MWBACKUP.INI *.DIF *.FUL *.INC *.SET *.SLT | Windows directory MSDOSDATA MSDOSDATA MSDOSDATA MSDOSDATA MSDOSDATA | Program directory Program directory Program directory Program directory Program directory |
MWUNDEL
| UNDELETE.INI
| MSDOSDATA
| Program directory
|
SCANDISK
| SCANDISK.INI
| MSDOSDATA
| Program directory
|
UNDELETE
| UNDELETE.INI
| MSDOSDATA
| Program directory
|
Table B.1, program directory refers to the directory that the executable program file is located in. Locations shown in all caps are environment variables that point to subdirectories. Programs that list both a primary and secondary location search for the data file in the primary location first.
If you set up a separate data subdirectory for MS-DOS, you might need to move some of these data files from your DOS subdirectory to that subdirectory. See the MOVE
command in Appendix F,“Command Reference,” for details about how to move a file.
The PATH
command stores its settings in the DOS environment under the PATH
variable name. (You can set the path by using either the PATH
or SET
command.) You probably should set the initial DOS search path in your AUTOEXEC.BAT
file. DOS does not define a default PATH
automatically, although the Setup program for DOS 6 does insert the PATH
command in your AUTOEXEC.BAT
file if you don't have one there already.
DOS uses the PATH
environment variable to find executable files. Whenever a command is executed, DOS searches for the first word on the command line in the following:
The DOSKEY
macro list, if DOSKEY
is loaded
The COMMAND.COM
internal command list
Files with an extension of COM
, then EXE
, and then BAT
in the current directory
Files with an extension of COM
, then EXE
, and then BAT
in the first directory listed in the PATH
variable
Files with an extension of COM
, then EXE
, and then BAT
in the second directory listed in the PATH
variable
Files with an extension of COM
, then EXE
, and then BAT
in the next directory listed in the PATH
variable, and so on until the last subdirectory in the PATH
variable has been searched
You can modify this order depending on what parts of the full pathname you enter with the command name. If you specify a drive or path with the filename, only that drive and path are searched. If you specify an extension, the other extensions are not searched for. The DOSKEY
macro and internal command search are skipped if you include a disk drive or path that includes a backslash in the name of the command, but not if you include only an extension.
Other programs might search the PATH
variable as well. Programs that require the addition of their subdirectory to the PATH
often use the PATH
environment variable to find overlay and help files.
The PROMPT
environment variable describes the type of command-line prompt you want DOS to use. It is set by the user with either the PROMPT
or SET PROMPT=
command. The default command-line prompt that DOS uses if the PROMPT
environment variable is undefined is the letter of the current drive and >
—for example, C>
.
If the PROMPT
environment variable doesn't exist, the DOS 6.0, 6.2, and 6.22 versions of COMMAND.COM
create it automatically with a value of $P$G
. This prompt shows the current directory as well as the current drive; for example, C:DOS>
. The only way to have the PROMPT
environment variable undefined is to delete it.
The PROMPT
environment variable uses meta-strings to include system information in the command prompt. For a description of which meta-strings are available and how they can be used, see the entry for PROMPT in the “Command Reference.”
Many programs use the TEMP
environment variable as the preferred place to create and delete temporary files. This environment variable evolved somewhat informally, which is why it has two popular spellings: TEMP
and TMP
. TEMP
is the more common variation and is the one DOS uses. Typically, if the TEMP
environment variable isn't defined, the program creates its temporary files in the root directory of the current drive (or sometimes the startup drive).
DOS creates the following types of files in the directory pointed to by the TEMP
environment variable:
Files required by the use of redirection (<
and >
) or piping (|
)
Swap files created by the DOS Shell Task Swapper
Temporary files created by any full-screen application program, such as MSAV
, MSBACKUP
, and QBASIC
Temporary disk data storage for DISKCOPY
Microsoft Windows Print Manager spooling files
Microsoft Windows swapping files (standard mode only)
Many programs use the TEMP
environment variable if it is defined. Temporary files that escape deletion by their parent program are easier to delete when they are gathered in their own subdirectory. Windows recommends at least 2MB in the subdirectory pointed to by the TEMP
environment variable. If you point TEMP
to a RAM disk, you never have to worry about deleting leftover temporary files. They all disappear whenever you reboot or turn off your computer.
Microsoft Windowsadds the windir
environment variable whenever you open a DOS window. The windir
environment variable always points to the main Windows directory, which is normally C:WINDOWS
. If you issue the SET
command to view the variables defined in a DOS window launched from Windows, the list might look like the following:
COMSPEC=C:DOSCOMMAND.COM PROMPT=$P$G PATH=C:BAT;C:DOS;C:WINDOWS;C:UTIL TEMP=C:TEMP TMP=C:TEMP windir=C:WINDOWS
Windows adds the windir
variable to the environment in lowercase letters to keep you from modifying or deleting it. If you issue a SET windir=
command, SET
capitalizes the variable name before searching for it, and a new variable named WINDIR
is created.
If the WINPMT
variable is defined, Microsoft Windows uses it to format the DOS prompt displayed in a DOS window. Using a different DOS prompt from Windows can help you remember that Windows is running and that you need to type EXIT
and quit Windows by pressing Alt+F4 before shutting off your computer.
To use the WINPMT
environment variable, define WINPMT
with the SET
command (perhaps in your AUTOEXEC.BAT
file) before you start Microsoft Windows. Set WINPMT
equal to the prompt you want to use from Windows, using the same formatting you use with the PROMPT
command.
For example, you can define the Windows prompt as a simple reminder:
SET WINPMT=**Windows** $P$G
This results in the following prompt in a DOS window:
**Windows** C:DOS>
Use the following if you prefer a more direct reminder of how to close a DOS window:
SET WINPMT=**Type EXIT to return to Windows** $P$G
This results in the following prompt in a DOS window:
**Type EXIT to return to Windows** C:DOS>
3.144.37.38