How to echo a new line in batch file

If you are looking for a solution to echo a new line in batch file, this article explains various ways to insert a new line in a command prompt using a batch script.

We will consider 2 aspects of printing a new line in batch script.

  1. How to add a new line between text.
  2. How to add some blank lines between your command execution (batch echo blank line).

To echo a new line in a batch file, you can create a new line character as ^^^%NLC%%NLC%^%NLC%%NLC% and echo it or use echo; or echo( or echo/ or echo+ or echo= in a single line to insert a blank line in between your code. Also, by using EnableDelayedExpansion you can achieve the blank line.

You may need any one of them in different situations. When you are running a series of utilities in a single batch file, you may need to echo a blank line between utility execution to have a clear view of the command prompt. Learn how echo new line in batch file works.

1. How to echo new line in batch file

a. By creating a newline character:

@echo off
REM Begin
set NLC=^

set NL=^^^%NLC%%NLC%^%NLC%%NLC%
REM End
echo Hello%NL%World

echo.
Pause

Note: The main code is between the REM statement. The two spaces are mandatory.

Output:
Hello
World

b. By using ‘EnableDelayedExpansion’:

@echo off
setlocal EnableDelayedExpansion
(set \n=^
%=This is Mandatory Space=%
)

echo Hello!\n!World

echo.
pause

Note: In place of ‘This is Mandatory Space, you can write anything of your own or just provide 4 spaces.

Output:
Hello
World

c. By using echo function call:

@echo off

echo Hello&echo,World

echo.
pause

Note: In place of echo, you can use echo; or echo( or echo/ or echo+ or echo=

Though echo. or echo: also yields the same result still it is not recommended to use those, as it may slow the execution process.

Output:
Hello
World

Click here to read other articles in Programming here.

2. How to echo a blank line between command execution in batch file

@echo off

@echo Executing Command1
@echo,
@echo(
@echo Executing Command2

Output:
Executing Command1


Executing Command2

Note: In place of echo, you can use echo; or echo( or echo/ or echo+ or echo=

echo. or echo: provides the same result but is not recommended to use, as they may slow down the execution process.

Some people recommend using ‘echo .’, it will print a dot(.) on the screen.

@echo off

@echo Executing Command1
@echo .
@echo Executing Command2

Output:
Executing Command1
.
Executing Command2

That’s how you echo a new line in a batch file. Hope you will make use of any one of the methods mentioned above.

Happy learning 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Scroll to Top