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:
A command line is scanned for variable specifications, and any found are replaced with the contents of those variables.
`Special characters can be quoted, to remove their special meanings.
Command lines are developed into a sequence of commands according to a syntax.
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
%USERNAME%, is replaced with the value of the named environment variable. For example,
%PATH% is replaced by the value of the PATH environment variable.
% for 0 <= n <= 9, such as
%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.
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
Special variable names and what they expand to:
You can prevent the special characters that control command syntax from having their special meanings as follows, except for the percent sign (