|
SET
Shows the environment values and allows them to be changed.
Syntax
set [[/a [expression]] [/p [variable=]] string]
Top of page
Parameters
/a : Sets string to a numerical expression that is
evaluated.
/p : Sets the value of variable to a line of input.
variable : Specifies the variable you want to set or
modify.
string : Specifies the string you want to associate with
the specified variable.
You may use the SET command to create your own internal
paramaters. This batch file:
@echo off
set myvar=Hi David
echo %myvar% is myvar
Will print Hi David is myvar. Notice a few important points.
When we initialize myvar there are no % around it. When we
use it, it must be between two %. Also, there must be no
spaces between the = and the terms. When myvar is not in a
set command or between % it is treated as a literal string.
You can make up your own parameter names and have many of
them:
@echo off
set name=John Smith
set address=1 main street
set city=helltown
echo %name%
echo %address%
echo %city%
You could also assign command line parameters to the
variables:
@echo off
set name=%1
set address=%2
set city=%3
echo %name%
echo %address%
echo %city%
The command line usually sees the space as a parameter
delimiter, use double quotes " to make it ingore the spaces:
test.bat "Joe Smith" "1 Main Street" "Helltown".
Something important to remember about SET, it actaully
creates a variable name in the file So if you enter
SET NAME=Joe on the command line or in a batch file and then
go to the command line and enter ECHO %NAME% the response
will be Joe. Entering SET with no parameters will also show
the whole list of SET variables. These will be erased when
you reboot.
Examples
To set an environment variable named TEST&1, type:
set testVar=test^&1
Batch File Commands
|