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:
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:
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:
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:
- Batch file introduction.
- Best Gifts for the programmer and techies.
- Best mouse for a programmer.
- File handling in C, In a few hours.
- List of Batch script commands.
- How to create variables in the batch script.
- Batch script to copy files from one folder to another folder.
- How to use if-else statements in the batch script.
- for loop in the batch file.
- How to pass parameters in a batch file.