Dos - Echo

About

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

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

How to

echo a blank line

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

echo[
echo.

echo in red or green color

You can echo in color with color terminal escape sequence

for /F %%a in ('"prompt $E$S & echo on & for %%b in (1) do rem"') do set "ESC=%%a"

then use it to create a control sequence

set TEXT=text to print
REM green
echo %ESC%[32m%TEXT %ESC%[0m
REM red
echo %ESC%[32m%TEXT %ESC%[0m

More color see batch_colors.cmd

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

Powered by ComboStrap