See also the pages on MS-DOS commands and
DOS has three kinds of "variables" special symbols that represent a
string of characters. The first kind command arguments are
only useful from within a batch file, but the other two are also available
at the DOS command line.
- Command arguments, named %1,
%9. If your batch file is named foo.bat, for
example, the command
foo yabba dabba doo
would have %1=yabba, %2=dabba,
%3=doo. (Incidentally, %0 would be
foo, a fact that is sometimes useful.)
So what happens if the command line has more than 9
arguments? The command shift shifts the arguments
"down" one step, so that the old %1 is forgotten, the new
%1 is the old %2, etc. and the new %9 is
the 10th argument on the line (or is blank if there were not that many
arguments). This command can be repeated as many times as necessary to
access all arguments.
- Environment variables, whose names can be any string of
numbers and letters. These are defined using the set
command, which (when entered by itself) shows a list of all current
environment variables. To use these in a command line or in a
batch file, place the name between percent symbols; for example,
%PATH% or %path% (names are not
DOS uses some names for
specific purposes. The variable DIRCMD gives
default options for the dir command; for example,
set dircmd=/oge /p
will cause directory listings to be
displayed with directories grouped at the top, sorted by extension, and
pausing for each screenful.
often has the value $p$g, tells DOS how to display the
prompt (the text that tells the user that the computer is waiting for
input). $p means "show the path of the current directory,"
and $g means to show a "greater than" sign. The
following setting allows you to display your school spirit with every
command you enter:
set prompt=Bluffton Beavers are the best!$_$p$g
(The characters $_ produce a "carriage return/line feed"
meaning that output continues on the next line.)
The variable PATH is a list of
directories that DOS searches (for batch files, etc.) when a command is
entered. If you enter the following line, DOS will look for batch files in
the root directory of the C: drive, in addition to
everywhere else it looks:
If \ is used instead of C:\, DOS will
search the root directory of the current drive.
- "For" variables, named
%%z. These are used with the FOR
command (described in the batch files
page), and the values of these variables are forgotten after that line.
If used on the command line, only one percent symbol is needed.