How MS-DOS 6.22 Processes Prompt Variables Like \(P\)G
In MS-DOS 6.22, the command interpreter COMMAND.COM
dynamically formats the command prompt by evaluating escape codes
defined in the PROMPT environment variable. This article
explains how the system stores this string, parses metacharacters such
as $P and $G, and executes low-level DOS
interrupts to retrieve system state information before printing the
prompt to the console.
The Role of the PROMPT Environment Variable
When you execute a command such as PROMPT $P$G or set it
in your AUTOEXEC.BAT, MS-DOS does not immediately evaluate
the values. Instead, it copies the literal string $P$G into
the master environment segment. If no PROMPT variable
exists in the environment, COMMAND.COM defaults to the
standard $N$G pattern (current drive letter followed by the
greater-than symbol).
The Prompt Parsing Loop in COMMAND.COM
Immediately before yielding control to the user for input,
COMMAND.COM prepares the interactive prompt using an
internal routine:
- Environment Lookup: The interpreter searches the
active environment block for the
PROMPT=entry. - Byte-by-Byte Scanning:
COMMAND.COMreads the string character by character from memory. - Literal Printing: Any character other than the
dollar sign (
$) is immediately output to the standard output device (typically via DOS Interrupt 21h, Function 02h). - Escape Evaluation: When the parser encounters a
$, it fetches the subsequent byte, converts it to uppercase, and matches it against an internal jump table.
Processing Specific Tokens
Each metacharacter instructs COMMAND.COM to perform a
specific action or system call:
$P(Current Drive and Path): To resolve$P,COMMAND.COMfirst queries the current default drive by calling INT 21h, Function 19h (Get Current Default Drive), which returns a zero-indexed integer (0 for A:, 1 for B:, 2 for C:). It converts this value to an ASCII letter, appends a colon and a backslash, and then calls INT 21h, Function 47h (Get Current Directory) to retrieve the full sub-path for that drive. If the drive is a removable medium (such as a floppy drive) and no disk is present, this call triggers the critical error handler (INT 24h), producing the familiar "Abort, Retry, Fail?" prompt.$G(Greater-Than Sign): Because the>character is the DOS redirection operator, it cannot always be safely passed or stored in plain scripts without unintended redirection. The parser substitutes$Gwith ASCII 62 (>) directly at the output stage.$N(Current Drive): Calls INT 21h, Function 19h and prints only the resulting drive letter, omitting the directory path.$Dand$T(Date and Time): These trigger INT 21h, Function 2Ah (Get System Date) and INT 21h, Function 2Ch (Get System Time), formatting the returned binary values into standard date and time strings.$E(ASCII Escape Character): Returns ASCII 27 (1Bh). This is commonly combined with theANSI.SYSdevice driver to send escape sequences that alter screen colors or cursor positions.$$(Literal Dollar Sign): Escapes the delimiter and outputs a single$character (ASCII 36).$_(Carriage Return / Line Feed): Outputs ASCII 13 and ASCII 10, forcing the remainder of the prompt onto a new line.
Terminal Output
After resolving each token, the resulting characters are sent
sequentially to standard output. Once the parser encounters the
null-terminator at the end of the PROMPT string, the
evaluation ends, and COMMAND.COM executes a blocking read
routine (typically INT 21h, Function 0Ah) to wait for
keyboard input at the end of the newly rendered prompt.