The parsing of a command line into a sequence of commands is complex, and varies subtly from command interpreter to command interpreter. There are, however, four main components:
Variable substitution
A command line is scanned for variable specifications, and any found are replaced with the contents of those variables.
Quoting
`Special characters can be quoted, to remove their special meanings.
Syntax
Command lines are developed into a sequence of commands according to a syntax.
Redirection
Redirection specifications are applied, and removed from the command line, before an individual command in a sequence is executed.
Command lines can contain variable specifications. These comprise a %
character followed by a name, followed by a second %
character unless the name is a digit in 0 ... 9 or an asterisk *.
Variable specifications are replaced with values as follows:
%%
, such as %PATH%
or %USERNAME%
, is replaced with the value of the named environment variable. For example, %PATH%
is replaced by the value of the PATH environment variable.
varname
%
for 0 <= n <= 9, such as %0
or %9
, is replaced with the value of the n-th parameter passed to the batch file when it was invoked, subject to any subsequent modifications by the SHIFT command. For example: %2
is replaced by the value of the second batch file parameter.
n
%* is replaced with the values of all the command-line parameters except for %0, even those beyond index 9. SHIFT command has no impact on the result of %*. See also command-line arguments.
Some variable names are not visible using SET command. Rather, they are made available for reading using the %
notation. To find out about them, type help set
.
Special variable names and what they expand to:
Links:
You can prevent the special characters that control command syntax from having their special meanings as follows, except for the percent sign (%
):