How can I echo a newline in a batch file?

How can you you insert a newline from your batch file output?

I want to do something like:

echo hello\nworld

Which would output:

hello
world

Solution 1:

Use:

echo hello
echo:
echo world

Solution 2:

echo hello & echo.world

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

Solution 3:

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.