How MS-DOS 6.22 Parses Batch Arguments %1 to %9
In MS-DOS 6.22, batch files use the replacement variables
%1 through %9 to capture positional command
line arguments passed during execution. This article explains how the
command processor COMMAND.COM tokenizes user input into
these variables, how it handles special delimiters and quotation marks,
the memory constraints governing command tails, and how to access
arguments beyond the initial nine using the SHIFT
command.
The Command Tail and Buffer Limits
When a batch file is invoked, MS-DOS stores the text typed after the
file name in the unformatted parameter area of the Program Segment
Prefix (PSP) at offset 80h. This area, known as the command
tail, has a maximum length of 127 characters.
Before the batch file executes, COMMAND.COM scans this
string from left to right, stripping leading separators and breaking the
input into distinct tokens assigned sequentially to %1,
%2, %3, up to %9. The variable
%0 is reserved for the command or batch file name itself as
typed on the command line.
Token Delimiters
MS-DOS 6.22 recognizes five distinct ASCII characters as argument delimiters:
- Space (
) - Horizontal Tab (
\t, ASCII 9) - Comma (
,) - Semicolon (
;) - Equals Sign (
=)
When COMMAND.COM encounters any of these characters, it
marks the end of the current positional argument. Contiguous sequences
of multiple delimiters (such as several spaces or a comma followed by a
space) are collapsed and treated as a single delimiter. For example, the
following command line:
MYBATCH.BAT first,second;third===fourth fifth
assigns the variables as follows:
%1=first%2=second%3=third%4=fourth%5=fifth
Lack of Quote Preservation for Grouping
Unlike modern Windows command interpreters (cmd.exe),
the MS-DOS 6.22 command interpreter does not recognize double quotes
(") as token-grouping characters.
If an argument containing spaces is enclosed in quotes,
COMMAND.COM treats the quotes as literal text rather than
grouping boundaries. It will still split the argument at the space
delimiter:
MYBATCH.BAT "C:\Program Files\App"
In this case:
%1receives"C:\Program%2receivesFiles\App"
Because MS-DOS 6.22 natively operates on the 8.3 FAT file system, long filenames and paths containing spaces were not supported natively, making delimiter escape mechanisms unnecessary in original DOS environments.
Accessing Arguments Beyond
%9
MS-DOS only provides direct variable references up to
%9. Any arguments passed past the ninth position on the
command line are stored in memory but cannot be accessed directly via
%10. Entering %10 in a script causes
COMMAND.COM to evaluate %1 and append a
literal 0 to the result.
To access subsequent arguments, the SHIFT command must
be used. Executing SHIFT discards the current value of
%0, moves %1 to %0,
%2 to %1, and so on, pulling %10
into the %9 position. This command is typically placed
inside a loop to process an arbitrary number of command line arguments
sequentially until all parameters are evaluated.