How can I echo a newline in a batch file?

There is a standard feature echo: in cmd/bat-files to write blank line, which emulates a new line in your cmd-output:

@echo off
echo line1
echo:
echo line2

or

@echo line1 & echo: & echo line2

Output of cited above cmd-file:

line1

line2

echo hello & echo.world

This means you could define & echo. as a constant for a newline \n.


Here you go, create a .bat file with the following in it :

@echo off
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%
REM Example Usage:
echo There should be a newline%NL%inserted here.

echo.
pause

You should see output like the following:

There should be a newline
inserted here.

Press any key to continue . . .

You only need the code between the REM statements, obviously.


Use:

echo hello
echo:
echo world