echo
has four basic usages:
-
echo some text
to print
some text
to the console
-
echo off
to turn off command echoing, compare with the
/q
options
.
-
echo on
to turn on command echoing
-
echo
to show if command echoing is turned off or on
Printing empty lines
echo
prints an empty line if the command is followed by a colon:
@echo:
@echo An empty line will be printed.
@echo:
@echo a colon following echo did the trick.
As per some answers and comments in
this stackoverflow thread
, the only (?) safe way is to use
echo(
.
With
echo(
, it's also possible to print
indented text
:
@echo( 1
@echo( 1 1
@echo( 1 2 1
@echo( 1 3 3 1
@echo( 1 4 6 4 1
Suppress traling new line
The bash built-in echo
command has the -n
options which suppresses new lines. Unfortunately (but not so surprisingly), cmd.exe's version of echo
does not have such an option. However, the new line of echo
can be piped into set /p
to write text without trailing new lines:
@echo off
echo | set /p="Writing "
echo | set /p="a "
echo | set /p="text "
echo | set /p="line "
echo | set /p="word "
echo | set /p="for "
echo word.
This «trick» is also used in the pc.bat
batch file which writes the current working directory into the clipboard.
See also