MS-DOS 6.22 Batch Parameter Parsing with Spaces

This article explains how the MS-DOS 6.22 command interpreter, COMMAND.COM, processes batch file parameters when spaces are involved. Unlike modern Windows command processors, MS-DOS 6.22 treats spaces as absolute token delimiters regardless of quotation marks. The following sections break down how COMMAND.COM tokenizes command-line arguments, how it handles quotation marks, and how to work around these limitations within pure DOS environments.

The Role of Delimiters in COMMAND.COM

In MS-DOS 6.22, COMMAND.COM relies on a strict set of delimiter characters to split command-line input into individual parameters (%1 through %9). These delimiters include:

  • Space ( )
  • Tab (\t)
  • Comma (,)
  • Semicolon (;)
  • Equals sign (=)

Whenever COMMAND.COM encounters any of these characters on the command line, it ends the current parameter token and begins the next. Consecutive delimiters (such as multiple spaces) are treated as a single separator unless an explicit empty value is maintained by certain specific command syntax.

Quotation Marks Do Not Group Strings

Modern shells (such as Windows cmd.exe or Unix shells) allow users to wrap arguments with spaces inside double quotes ("...") to pass them as a single token. MS-DOS 6.22 does not support this behavior natively.

In MS-DOS 6.22, the double-quote character is treated merely as a literal text character rather than a grouping operator. It does not escape or suppress the delimiter properties of spaces.

For example, if you invoke a batch script named RUN.BAT with the following command:

RUN.BAT "C:\Program Files\App"

MS-DOS 6.22 will parse the parameters as follows:

  • %1 receives "C:\Program
  • %2 receives Files\App"

Because the space separates the two words, the quoted string is fragmented across two distinct variables, with the leading and trailing quote characters remaining attached to the split strings.

Practical Workarounds in MS-DOS 6.22

Because COMMAND.COM cannot natively keep space-delimited text within a single variable, developers using MS-DOS 6.22 must use specific techniques to process input containing spaces:

1. Recombining Tokens with the SHIFT Command

If an unknown number of spaces might be passed, you can read the first parameter, append it to an environment variable, and use SHIFT in a loop to rebuild the original string.

@ECHO OFF
SET FULLSTR=
:LOOP
IF "%1"=="" GOTO DONE
IF "%FULLSTR%"=="" (SET FULLSTR=%1) ELSE (SET FULLSTR=%FULLSTR% %1)
SHIFT
GOTO LOOP
:DONE
ECHO Result: %FULLSTR%

This reconstructs the spaced string inside the FULLSTR variable, though quotes must be handled or stripped manually if present.

2. Using Environment Variables Instead of Arguments

The most reliable method for passing strings containing spaces in MS-DOS 6.22 is to define the value in an environment variable before executing the batch file:

SET TARGET=C:\MY DIR\TARGET
RUN.BAT

Inside RUN.BAT, referencing %TARGET% directly bypasses the command-line argument tokenizer entirely, preserving spaces accurately without token fragmentation.