Search notes:

cmd.exe: the echo command

Four basic usages of echo

echo has four basic usages:

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.
Github repository about-cmd.exe, path: /commands/echo/empty-line.bat
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.
Github repository about-cmd.exe, path: /commands/echo/suppress-new-line.bat
This «trick» is also used in the pc.bat batch file which writes the current working directory into the clipboard.

See also

Other cmd.exe commands

Index