How do I force the ECHO command to echo?

Raymond Chen

The ECHO built-in command, how much simpler could it get? It takes whatever you put on the command line and prints it. And yet it’s not that simple.

For example, the ECHO must be careful not to compress whitespace, because people will write

ECHO Some text
ECHO    Indented text
ECHO             ----     underlined

and when you execute this, the result had better be

Some text
   Indented text
            ----     underlined

and not

Some text
Indented text
---- underlined

But what if you want to echo a blank line or the word “ON” or “OFF” or a slash and a question mark?

ECHO is on.
C:\> ECHO /?
Displays messages, or turns command-echoing on or off.

To force the ECHO command not to interpret its arguments, put a dot immediately after the word “echo”:

C:\> ECHO.    ON
C:\> ECHO.
C:\> ECHO./?

This is what happens when a language develops not by design but by evolution. It becomes filled with all sorts of strange quirks in order to accommodate new behavior while remaining compatible with old behavior. Nobody actually likes the batch language; they just are used to it.


Discussion is closed.

Feedback usabilla icon