FreeDOS PROMPT: Expansion Codes, ANSI Boundaries, and Reproducible Prompts
Configure FreeDOS PROMPT escape codes safely, distinguish shell formatting from ANSI driver behavior, and keep diagnostic prompts useful across boot profiles.
The FreeDOS PROMPT command changes the text that COMMAND.COM / FreeCOM displays before accepting the next command. Its dollar-prefixed codes expand into values such as the current drive and path, the date, the time, or a line break. Some users also place an Escape sequence in the prompt to request colors. That second behavior depends on a console driver that interprets ANSI control sequences; PROMPT emits the character, but it is not itself a video-mode or color driver.
For operations, a prompt should make the current location and shell state easier to recognize without hiding them behind decoration. A custom prompt can reduce mistakes during recovery work, but a color-only cue is not reliable in every emulator, display mode, or driver configuration. Prefer visible text and a drive/path indicator as the baseline.
Documented PROMPT codes
The FreeDOS help lists these codes: $$ for a literal dollar sign, $_ for carriage return and line feed, $B for a pipe character, $D for the current date, $E for Escape, $G for >, $H for backspace, $L for <, $N for the current drive, $P for the current drive and path, $Q for =, $T for the current time, and $V for the FreeDOS command-shell version number.
The default prompt is equivalent to the familiar current path followed by a greater-than sign. A practical diagnostic prompt could be:
prompt $N$P$G
This displays the current drive and path before the input cursor. It is more operationally useful than a decorative string when switching among removable media, recovery volumes, and multiple boot configurations.
$N and $P are not interchangeable. $N identifies only the current drive, while $P includes the current drive and directory. $D and $T are presentation values, not a time source integrity check. If the RTC is wrong, they faithfully display the DOS-visible date/time but do not correct it. $V identifies a shell version string, not necessarily the complete FreeDOS kernel, driver, or package set. Record actual system versions separately in a support ticket.
$E is an output byte, not color support by itself
The $E code emits the ASCII Escape character. FreeDOS’s prompt documentation describes using it with an ANSI color sequence when NANSI.SYS is loaded. NANSI or another compatible driver interprets the sequence; without such a driver, a terminal may display control characters, ignore them, or handle them differently. Do not assume that the BIOS video mode or a modern terminal emulator supplies the same behavior.
A conceptual color prompt might use an ANSI sequence after the visible path:
prompt $P$G$E[0m
This requests a reset sequence only if the console driver supports that convention. Test it in the target machine or emulator, then verify that ordinary text remains readable and the terminal is returned to a neutral state. Avoid relying on color as the only indication that a prompt is privileged, dangerous, or pointed at a production volume.
Escape sequences are stateful output sent to the console. A sequence that changes foreground, background, cursor position, or display mode can affect subsequent output until another sequence resets it. Keep the prompt sequence short, document what the code does, and test after loading or removing NANSI. If color behavior becomes confusing, return to a plain $P$G prompt rather than changing several display settings at once.
Set, test, and restore one prompt at a time
PROMPT can be typed interactively or placed in a startup batch file. Running it without a text argument resets the prompt to its default. Make a temporary change at the prompt first; do not edit AUTOEXEC.BAT or FDAUTO.BAT until the exact string has been tested.
For example:
prompt $P$G
cd \freedos\bin
The first command should show the new prompt. Changing directory then checks that $P updates on the next prompt rather than remaining a stale string. To restore the default, run:
prompt
If the prompt is malformed, type the command without arguments to restore a known baseline. Keep a recovery path that does not depend on interpreting color codes or navigating with a visually ambiguous cursor.
In a startup file, put the command after any driver required for its appearance. If $E precedes an ANSI sequence, load NANSI.SYS or the selected compatible driver earlier in the startup process. A prompt that uses only $P and $G has fewer dependencies and is generally safer for minimal or rescue boot profiles.
Common mistakes and compatibility boundaries
One common mistake is writing $P when a literal dollar sign was intended. Use $$ for a literal dollar according to FreeDOS documentation. Another is assuming $V reports every installed component; it is the shell version token. A third is testing an ANSI-colored prompt in an emulator that interprets escape codes itself, then deploying it to hardware without an ANSI driver. The same string can therefore have a different visual effect across environments.
Avoid placing lengthy multi-line artwork or untrusted variable text in a prompt. A prompt appears repeatedly and should remain concise enough that the current path and typed command are visible. If a tool changes the current directory unexpectedly, $P exposes that state; a static prompt can hide it. If date/time display is operationally important, compare it against an independent time source instead of treating the prompt as evidence that the machine clock is correct.
When a startup change makes interaction difficult, boot the alternate FreeDOS configuration or use a recovery disk to edit the startup file. Keep a backup before changing the persistent prompt. A prompt is a user-interface choice, not a substitute for a clearly labeled volume, verified path, or destructive-operation confirmation.
For a multi-configuration installation, keep the prompt policy local to the profile that needs it. A recovery profile should favor the path and drive tokens, while a minimal profile may use a shorter prompt only if users can still verify where commands will run. Store the chosen string in a comment beside the command and avoid duplicating it in several startup files. If profiles load different ANSI drivers, test each one separately because a driver may reset screen state or use a different supported subset.
When diagnosing a prompt issue, distinguish expansion from rendering. First set a plain prompt containing $N, $P, and $G; confirm the displayed drive and directory. Then add one code at a time, such as $D or $_. Only after the visible characters are correct should an Escape sequence be added. This sequence of tests can tell whether FreeCOM expanded the code, whether the driver interpreted it, or whether the display path mishandled the result.
Avoid using PROMPT as a substitute for an explicit confirmation dialog. A colored path may disappear when output is redirected or look different in a remote console. Destructive scripts should print their target and ask for explicit confirmation or require a reviewed configuration value; they should not infer safety from the prompt’s appearance.
Validation checklist
Verify each code in the exact shell being used: literal dollar, line break, pipe, date/time, drive, path, version, and Escape. Confirm that the prompt tracks directory changes, renders correctly with the intended ANSI driver, and remains legible when the driver is absent. Test the no-argument reset and retain a plain-text fallback in rescue configurations.
FreeDOS PROMPT is a small command with meaningful operational consequences. Use its documented expansions for context, keep $E separate from the driver’s interpretation of ANSI sequences, and make the final prompt testable and readable rather than merely colorful.
Related:
- ANSI Console Drivers on FreeDOS: Escape Sequences, NANSI, and Compatibility
- FreeCOM Interactive Command-Line Editing: History, Cursor Keys, and Completion
Sources: