How to echo a new line in batch file

Like other scripting languages, we can also echo a new line in a batch file. If you are searching for a solution to how to echo a new line in a batch file, then this article for you. There are many ways to echo the new line but here I will only explain the sample to print a ‘new line’ in the batch script.

 

Different ways to echo new line in batch file:

 

1. Using echo function call:

We can echo a blank line on the screen using any type of echo.

echo,

echo;

echo(

echo/

echo+

echo=

echo.

echo\

echo:

 

Now let’s see an example of how to echo a new line in a batch file.

@echo off

echo Hi&echo\Aticleworld

pause

While running this batch file:

echo new line batch file

 

This means you could define &echo\ as a constant for a newline \n. You can use any one of the above-mentioned echo types.

 

2. Using ‘EnableDelayedExpansion’:

 

@echo off

setlocal EnableDelayedExpansion
(set \n=^
%=Don't remove this line=%
)

echo Hi!\n!Aticleworld

pause

Output:

print new line in batch script

 

Note: In place of “Don’t remove this line”, you can write anything.

 

3. Using new line variable hack:

 

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


set NL=^^^%NLC%%NLC%^%NLC%%NLC%
REM Example Usage:
echo Hi%NL%Aticleworld.

pause

Output:

echo new line in batch script

 

 

Different ways to echo a blank line in batch file:

At the beginning of the article, I have already explained that using the echo command you can echo a blank line. You can use any one of the echo types which have mentioned above like echo. , echo, or echo; …etc.

Let’s see some example batch script to see how we can echo blank lines in the batch file.

Using the echo,

@echo off

@echo HI

@echo,

@echo Aticleworld

pause

Output:

HI

Aticleworld

 

Using echo.

@echo off

@echo HI

@echo.

@echo Aticleworld

pause

Output:

HI

Aticleworld

 

Note: Don’t include a space before the period. Otherwise, the period appears instead of a blank line. Let’s see an example script to understand this point.

@echo off

@echo HI

@echo .

@echo Aticleworld

pause

Output:

HI
.
Aticleworld

 

 

Recommended Articles for you:

Leave a Reply

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