Echo


Applies To: Windows Vista,Windows Server 2008

Displays messages or turns on or off the command echoing feature. If used without parameters, echo displays the current echo setting.

For examples of how to use this command, see Examples.

Syntax


Copy Code

echo [<Message>]
echo [on | off]

Parameters

Parameter

Description

[on | off]

Turns on or off the command echoing feature. Command echoing is on by default.

<Message>

Specifies the text to display on the screen.

/?

Displays help at the command prompt.

Remarks

Examples

To display the current echo setting, type:


Copy Code

echo

To echo a blank line on the screen, type:


Copy Code

echo.

Note

Do not include a space before the period. Otherwise, the period will be displayed instead of a blank line.

To prevent echoing commands at the command prompt, type:


Copy Code

echo off

Note

When echo is turned off, the command prompt does not appear in the Command Prompt window. To display the command prompt again, type echo on.

To prevent all commands in a batch file (including the echo off command) from displaying on the screen, on the first line of the batch file type:


Copy Code

@echo off

You can use the echo command as part of an if statement. For example, to search the current directory for any file with the .rpt file name extension, and to echo a message if such a file is found, type:


Copy Code

if exist *.rpt echo The report has arrived.

The following batch file searches the current directory for files with the .txt file name extension, and displays a message indicating the results of the search:


Copy Code

@echo off
if not exist *.txt (
echo This directory contains no text files.
) else (
  echo This directory contains the following text files:
  echo.
  dir /b *.txt
  )

If no .txt files are found when the batch file is run, the following message displays:


Copy Code

This directory contains no text files.

If .txt files are found when the batch file is run the following output displays (for this example, assume the files File1.txt, File2.txt, and File3.txt exist):


Copy Code

This directory contains the following text files:
File1.txt
File2.txt
File3.txt

Additional references

Command-Line Syntax Key