Set

Index

The Set command is used to display, set, or remove MS-Dos environment variables.

Syntax:

To set an environment variable:
SET envirovariable=string

To remove an environment variable:
SET envirovariable=

To display all current environment variables:
SET
envirovariableThe environment-variable name.
stringA series of characters to assign to the variable.

Notes:

  1. To use an environmental variable either from the command line or in a batch file, it must be enclosed in % signs as in %envirovariable%.

  2. Environment variables are typically used in three ways:
    • to assign a path to a variable. Many programs will create such a variable during installation to simplify access to temporary, data, and utility files used by the program. Such programs will automatically modify Autoexec.bat or Config.sys to include a SET line defining the variable.
    • to modify the defaults of a number of Dos commands by assigning the new defaults to Standard Environment Variables (see below).
    • as variables in batch files. Unlike the numbered variables %0 to %9, environmental variables are stored until they are reset or the command interpreter terminates (Window closed).

  3. If SET is used to assign string to a variable that already exists, the new value replaces the old.

  4. Environmental variables are stored in memory allocated by Command.com. If there is insufficient environment space for a new variable, and error message is displayed. (To increase the environment space, see COMMAND).

The Standard Environment Variables:

TMP and TEMP
Both used by programs to refer to a directory for temporary files.
Default: TMP=c:\windows\temp; TEMP=c:\windows\temp
PROMPT
Used to specify the starting Dos prompt.
Default: PROMPT=$P$G
WINBOOTDIR
Used to specify the directory containing Win.com - the Dos program that starts installing Win95.
Default: WINBOOTDIR=c:\windows
COMSPEC
Used to reference command.com from anywhere.
Default: COMSPEC=c:\windows\command.com
PATH
Used to specify directories to be included in the search path for executable files.
Default: PATH=c:\windows;c:\windows\command
WINDIR
Used to specify the Windows directory.
Default: WINDIR=c:\windows
COPYCMD
Used to specify whether the COPY, MOVE, and XCOPY commands should prompt for confirmation before overwriting a file.
To force a prompt before overwriting, COPYCMD is set to /-Y.
To force overwriting without prompting, COPYCMD is set to /Y.
Default: Empty
Eg. SET COPYCMD=/Y
DIRCMD
Used to change the default listing format by the DIR command by adding the appropriate switches - see DIR for the list.
Default: Empty
Eg. SET DIRCMD=/A/P

In addition to the above, many programs will set environmental variables without checking to see if the names are free. These variables are almost like trade names. I suspect it would be considered bad form (if not worse) to distribute a program that set a variable called "Blaster".

Variable NameCompany
BlasterCreative Labs Soundblaster
More to be added!

Examples:

To establish an environment variable named INCLUDE so that the string "c:\inc" (the "inc" directory on drive c:) is associated with it:
SET include=c:\inc

Once this command has been issued, the string "c:\inc" can be referenced at any time by using the term %include%.

Now, if several batch files are written to process files in the "c:\inc" directory, each reference to "c:\inc" can be made via the variable %include%.

Should the "inc" directory be moved or renamed, the batch files need not be altered: the INCLUDE variable would simply be reassigned to the new directory.

File Details:

Internal


If you should have any comments or suggestions,
please contact: Bob Watson
.
This page last revised:
December 9, 1999.