Echo a blank (empty) line to the console from a Windows batch file
Solution 1
Note: Though my original answer attracted several upvotes, I decided that I could do much better. You can find my original (simplistic and misguided) answer in the edit history.
If Microsoft had the intent of providing a means of outputting a blank line from cmd.exe
, Microsoft surely would have documented such a simple operation. It is this omission that motivated me to ask this question.
So, because a means for outputting a blank line from cmd.exe
is not documented, arguably one should consider any suggestion for how to accomplish this to be a hack. That means that there is no known method for outputting a blank line from cmd.exe
that is guaranteed to work (or work efficiently) in all situations.
With that in mind, here is a discussion of methods that have been recommended for outputting a blank line from cmd.exe
. All recommendations are based on variations of the echo
command.
echo.
While this will work in many if not most situations, it should be avoided because it is slower than its alternatives and actually can fail (see here, here, and here). Specifically, cmd.exe
first searches for a file named echo
and tries to start it. If a file named echo
happens to exist in the current working directory, echo.
will fail with:
'echo.' is not recognized as an internal or external command,
operable program or batch file.
echo:
echo\
At the end of this answer, the author argues that these commands can be slow, for instance if they are executed from a network drive location. A specific reason for the potential slowness is not given. But one can infer that it may have something to do with accessing the file system. (Perhaps because :
and \
have special meaning in a Windows file system path?)
However, some may consider these to be safe options since :
and \
cannot appear in a file name. For that or another reason, echo:
is recommended by SS64.com here.
echo(
echo+
echo,
echo/
echo;
echo=
echo[
echo]
This lengthy discussion includes what I believe to be all of these. Several of these options are recommended in this SO answer as well. Within the cited discussion, this post ends with what appears to be a recommendation for echo(
and echo:
.
My question at the top of this page does not specify a version of Windows. My experimentation on Windows 10 indicates that all of these produce a blank line, regardless of whether files named echo
, echo+
, echo,
, ..., echo]
exist in the current working directory. (Note that my question predates the release of Windows 10. So I concede the possibility that older versions of Windows may behave differently.)
In this answer, @jeb asserts that echo(
always works. To me, @jeb's answer implies that other options are less reliable but does not provide any detail as to why that might be. Note that @jeb contributed much valuable content to other references I have cited in this answer.
Conclusion: Do not use echo.
. Of the many other options I encountered in the sources I have cited, the support for these two appears most authoritative:
echo(
echo:
But I have not found any strong evidence that the use of either of these will always be trouble-free.
Example Usage:
@echo off
echo Here is the first line.
echo(
echo There is a blank line above this line.
Expected output:
Here is the first line.
There is a blank line above this line.
Solution 2
Any of the below three options works for you:
echo[
echo(
echo.
For example:
@echo off
echo There will be a blank line below
echo[
echo Above line is blank
echo(
echo The above line is also blank.
echo.
echo The above line is also blank.
Solution 3
There is often the tip to use 'echo.'
But that is slow, and it could fail with an error message, as cmd.exe will search first for a file named 'echo' (without extension) and only when the file doesn't exists it outputs an empty line.
You could use echo(
. This is approximately 20 times faster, and it works always. The only drawback could be that it looks odd.
More about the different ECHO:/\
variants is at DOS tips: ECHO. FAILS to give text or blank line.
Related videos on Youtube
DavidRR
Updated on April 23, 2020Comments
-
DavidRR about 4 years
When outputting status messages to the console from a Windows batch file, I want to output blank lines to break up the output. How do I do this?
-
DavidRR over 10 yearsI do not believe that the question How can you echo a newline in batch files? is a duplicate of this question. The essence of that question is: Using a single
echo
statement, how can I output two lines of text with a newline between them? That said, several of the answers to that question also address how to output blank (empty) lines. -
H2ONaCl over 7 yearsSince this post is not accepting answers anymore... The correct answer is
echo:
according to the following link. ss64.com/nt/echo.html -
u8it over 6 yearsIn summary of the ss64 link posted for
echo
...echo.
searches for a file namedecho
and only creates a blank line if such a file does not exist. This characteristic makesecho.
slower and less robust thanecho:
.
-
-
Taylor Hx over 10 yearsDo you have a source that highlights this issue?
-
Matteo Italia over 10 yearsIMHO it's completely pointless to worry about speed in batch - if your performance bottleneck lies in a batch file you don't try to optimize it - you throw it away to rewrite it in a real language.
-
Pacerier almost 9 yearsCareful, "
echo.
" might not work, see the comments under stackoverflow.com/questions/132799/… -
Pacerier almost 9 years@MatteoItalia, It's nothing to do with speed. If it's doing something extra (search first for a file named
echo
without extension) then it's wrong and if there's a file as such, it'll indeed fail. Extra points if the batchjob fails on a weekend while everyone is partying hard half-a-country away. -
Pacerier almost 9 years@jeb, What about newer versions of Windows?
-
jeb over 8 years@Pacerier It seems to be the same behaviour from XP to Win10, there are only very small changes since XP at all
-
tomasz86 over 5 years
echo.
,echo:
, echo\,echo+
,echo/
,echo[
, andecho]
are not safe. When used in afor /r
loop, e.g.for /r %a (*) do echo.%a
and so on, they append paths from the previous folder to the next one.echo(
,echo,
,echo;
, andecho=
do not have this problem. -
Cadoiz about 3 yearsAlso don't type a space between
echo .
like stupid me.