Dos - Echo

About

Displays messages, or turns command-echoing on or off.

If you use special character, don't forget to escape them.

Syntax

Display Messages

echo my beautiful message
my beautiful message

Configuration

Syntax

Turns command echoing on or off

ECHO [ON | OFF]

where:

  • ON is the default

You don't turn on or off the echo function, you turn on or off the echoing of the command.

The Rem command is never echoed

Example

  • With the following bat, echo is by default on
echo my Echo
  • By starting it, you get
> echo my Echo 
my Echo
  • By echoing off, you will get
echo off
echo my Echo
>echo off 
my Echo
  • To suppress the echoing of the echo off, use the @ special character
@echo off
echo my Echo
my Echo

Special Character

At

If a line is prefixed by the special character “@”, the block command will not be echoed to standard output (if echo is turned on) but

an echo message will

Example:

  • the following bat file will list the content of a directory (test.bat and my.bat)
for %%v in (*.*) do (echo %%v)
>for %v in (*.*) do (echo %v ) 
>(echo my.bat ) 
my.bat
>(echo test.bat ) 
test.bat
  • If you don't want to see the (echo …) message, change your file as below:
for %%v in (*.*) do @(echo %%v)
>for %v in (*.*) do @(echo %v ) 
my.bat
test.bat
  • and if you don't want to see the for statement,
@for %%v in (*.*) do @(echo %%v)
my.bat
test.bat
  • of course, you can turn off globally (and then not by block command)
@echo off
for %%v in (*.*) do (echo %%v)
my.bat
test.bat

How to

echo a blank line

Just add the special characters bracket or period just after the echo command

echo[
echo.

Powered by ComboStrap