MS-DOS 6.22 ECHO Command in Batch Execution

In MS-DOS 6.22, the ECHO command serves two primary functions during batch file execution: controlling the visibility of executed commands on the screen and printing custom text messages directly to the console or other output streams. By manipulating this command, users can either debug their batch routines by tracking execution step-by-step or conceal the underlying code to present a clean, professional command-line interface.

Controlling Command Display

By default, the MS-DOS command interpreter (COMMAND.COM) operates with command echoing enabled. This means that as a batch file executes, every single line of code is displayed on the monitor immediately before MS-DOS runs it.

  • ECHO OFF: Suppresses the display of subsequent commands in the batch file. When active, only the output produced by the programs or commands themselves is visible to the user.
  • ECHO ON: Restores the default behavior, forcing the command interpreter to display each command line before it executes. This is particularly useful for troubleshooting and debugging scripts.
  • The @ Symbol: Placing an @ symbol at the beginning of any command suppresses the display of that specific line. Consequently, @ECHO OFF is standard practice at the beginning of MS-DOS 6.22 batch files to hide the ECHO OFF instruction itself while disabling echoing for all subsequent lines.

Displaying Messages and Formatting

Beyond controlling command visibility, ECHO functions as a standard print command inside batch scripts:

  • Printing Text: Running ECHO [message] prints the specified string directly to the screen. This allows batch files to provide status updates, instructions, or warning messages to the user.
  • Printing Blank Lines: Running ECHO. (with no space between the word and the period) outputs a single blank line. This technique is commonly used to format terminal text and improve readability.
  • Querying Status: Executing ECHO on a line by itself prompts the interpreter to return the current echo state, reporting either ECHO is on or ECHO is off.

Output Redirection

The ECHO command is also widely used to generate and modify files directly from batch scripts via standard DOS redirection operators:

  • Creating or Overwriting Files: ECHO text > filename.txt creates a new text file or overwrites an existing one containing the designated text.
  • Appending to Files: ECHO text >> filename.txt adds the text to the end of an existing file.
  • Hardware Output: Text can be routed to physical devices, such as sending control strings or text directly to a parallel printer using ECHO text > PRN.