New Line in Batch Script

MD Aminul Islam Jun 21, 2022
  1. Use echo to Create a New Line in Batch
  2. Use EnableDelayedExpansion to Create a New Line in Batch
  3. Generate a New Line by Creating a Variable in Batch
New Line in Batch Script

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:

  1. echo,
  2. echo;
  3. echo(
  4. echo/
  5. echo+
  6. echo=
  7. echo.
  8. echo\
  9. 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
MD Aminul Islam avatar MD Aminul Islam avatar

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

Related Article - Batch File