New Line in Batch Script
-
Use
echo
to Create a New Line in Batch -
Use
EnableDelayedExpansion
to Create a New Line in Batch - Generate a New Line by Creating a Variable in Batch
We can echo
a new line in Batch scripts like other programming and scripting languages. You can follow this article if you are looking for a way to echo
in a new line.
In this article, we’re going to show different ways to echo
in a new line. Also, we will see necessary examples with explanations to make the topic easier to understand.
Use echo
to Create a New Line in Batch
Below we listed some echo
types that can be used to make a new line. These are:
echo,
echo;
echo(
echo/
echo+
echo=
echo.
echo\
echo:
Below is an example and its output regarding this method.
@ECHO off
ECHO This is a line&ECHO\This is a new line
PAUSE
After running the script, you will get an output like the one below.
This is a line
This is a new line
Use EnableDelayedExpansion
to Create a New Line in Batch
Using EnableDelayedExpansion
, you can also create a new line. To do this, you need to follow the below example.
@ECHO off
SETLOCAL EnableDelayedExpansion
(set \n=^
%=Do not remove this line=%
)
ECHO This is a line!\n!This is a new line
PAUSE
After running the script, you will get an output like the one below.
This is a line
This is a new line
Generate a New Line by Creating a Variable in Batch
We also can generate a new line by creating a variable. To do this, you have to follow the below example.
@ECHO off
ECHO This is a line
REM Creating a gap with echo
ECHO:
ECHO This is a new line
PAUSE
After running the script, you will get an output like the one below.
This is a line
This is a new line
Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.
LinkedIn