|
SET
Displays, sets, or removes environment variables.
SET variable
SET variable=string
SET /A variable=expression
SET "variable="
SET /P variable=[promptString]
SET "
Key
variable : A new or existing environment variable name
string : Specifies the string you want to associate
with the specified variable.
expression: : Arithmetic Sum
When you type the set command alone, the current environment
settings are displayed.
Variable names are not case sensitive but the contents can
be. Variables can contain spaces.
When you specify values for variable and string, the
specified variable value is added to the environment and the
string is associated with that variable. If the variable
already exists in the environment, the new string value
replaces the old string value.
When creating batch files, you can use SET to create
variables and use them in the same way that you would the
numbered variables %0 through %9. You can also use the
variables %0 through %9 as input for SET.
When you call a variable value from a batch file, enclose
the value with percent signs (%). For example, if your batch
program creates an environment variable named BAUD, you can
use the string associated with BAUD as a replaceable
parameter by typing %baud% at the command line.
The number one problem people run into with SET is having
extra spaces around either the variable name or the string,
SET is not forgiving of extra spaces like many other
scripting languages.
Examples
Set sets the variable value as everything following the
equals sign (=). If you type:
set testVar="var^1"
You get the following result:
testVar="var^1"
To set an environment variable named VAR^1, type:
set testVar=var^^1
To set an environment variable named INCLUDE so that the
string C:\Doc is associated with it, type:
set include=c:\doc
You can then use the string C:\Doc in batch files by
enclosing the name INCLUDE with percent signs (%). For
example, you might include the following command in a batch
file so that you can display the contents of the directory
associated with the INCLUDE environment variable:
dir %include%
When this command is processed, the string C:\Doc replaces
%include%.
Cmd Commands
|