April 3rd, 2008

How do I force the ECHO command to echo?

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?

C:\> ECHO ON
C:\> ECHO
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
    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.

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.