MS-DOS 6.22 Environment Variables in Command Paths

In MS-DOS 6.22, handling command execution paths that involve system environment variables relies entirely on the command processor, COMMAND.COM. This article explains how MS-DOS parses environment variables in executable paths, the critical distinction between interactive command-line entry and batch script execution, how the PATH variable operates, and the system limitations that govern path evaluation.

Interactive Command Line vs. Batch Processing

The primary constraint of MS-DOS 6.22 is that COMMAND.COM does not natively expand environment variables typed directly into the interactive command prompt. If a user attempts to execute a command using variable syntax at the prompt—such as %BINDIR%\TOOL.EXE—the command processor treats the percent signs (%) as literal characters. Consequently, the operating system attempts to locate a directory physically named %BINDIR% and returns the standard error: Bad command or file name.

Environment variable expansion for command paths only occurs when the command is executed from within a batch file (.BAT). When a batch script runs, the parser preprocesses each line, replaces any %VARIABLE% tokens with their corresponding string values from the MS-DOS environment block, and then passes the fully resolved string to the execution engine.

Static Expansion vs. Dynamic Evaluation

MS-DOS 6.22 does not support dynamic late-binding of paths stored in environment variables. Variable evaluation happens strictly at parse time.

For instance, when configuring the global search path in AUTOEXEC.BAT using a command like SET PATH=C:\DOS;%MYTOOLS%, the parser substitutes the current value of MYTOOLS at the exact moment the line executes. The resulting PATH variable stores only the raw, expanded ASCII string. If the value of MYTOOLS changes later during the session, the PATH variable does not automatically update; it retains the static value assigned during the initial execution.

Command Lookup and the PATH Variable

When a user executes an external command without specifying an absolute or relative directory path (e.g., typing EDIT rather than C:\DOS\EDIT.COM), COMMAND.COM follows a rigid resolution sequence:

  1. It checks if the command is an internal shell command (e.g., DIR, COPY).
  2. It searches the current working directory for matching executable file extensions in order: .COM, .EXE, and .BAT.
  3. It queries the PATH environment variable.

The command processor reads the PATH string sequentially, splitting entries delimited by semicolons (;). It inspects each directory from left to right, stopping immediately when the first matching executable is located. If an entry within the PATH string contains unexpanded syntax—such as a literal %FOO% caused by setting the variable from the interactive prompt—MS-DOS will fail to find the directory and will silently move to the next semicolon-delimited path.

Memory and Buffer Limitations

Command path resolution with environment variables is constrained by strict memory limits inherent to MS-DOS 6.22:

  • Command Buffer Limit: COMMAND.COM maintains a maximum command-line buffer of 127 characters. When variables are expanded inside a batch file, the total length of the resulting command line—including fully expanded paths, executable names, and switches—must not exceed this 127-character threshold. Any characters beyond this limit are truncated, typically causing execution failures or syntax errors.
  • Environment Block Size: The default environment block in MS-DOS 6.22 is only 256 bytes. Long path definitions containing multiple concatenated variables can easily exhaust this memory pool, resulting in the error Out of environment space. Users often need to expand this space manually using the SHELL=C:\DOS\COMMAND.COM /E:xxxx /P directive in CONFIG.SYS.