Name

echo

Synopsis

Display a string of text; turn command echoing on or off.

Syntax

echo [on | off  | message]

Description

Echo is typically used with other commands or in a batch file to display text on the screen. It’s also used to control command echoing from batch files.

The following options can be used with echo :

on | off

By default, each command in a batch file is echoed to the screen as it is executed. Echo on and echo off toggles this feature. To turn echoing off without displaying the echo off command, use @echo off. The @ symbol in front of any command in a batch file prevents the line from being displayed.

message

Types the message you’d like displayed to the console (screen).

Examples

To display an ordinary message, use the following:

echo Hello World!

To display a blank line, use one of the following (all equivalent):

echo.
echo,
echo"

(Note the absence of the space between the echo command and the punctuation; you can also use a colon, semicolon, square brackets, backslash, or forward slash.)

One handy use of echo is to answer y to a confirmation prompt such as the one del issues when asked to delete all the files in a directory. For example, if you wanted to clear out the contents of the \temp directory from a batch file, you could use the following command:

echo y | del c:\temp\*.*

or even:

echo y | if exists c:\temp\*.* del c:\temp\*.*

This construct works because the pipe character takes the output of the first command and inserts it as the input to the second.

Announce the ...

Get Windows XP in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.