The issue of multi-line strings in BAT commands

In BAT commands, to create a multi-line string, you can use the ^ symbol to connect multiple lines and use the echo command to output it. Here is an example:

@echo off
setlocal EnableDelayedExpansion

set "multiLine=This is line 1. ^
This is line 2. ^
This is line 3."

echo %multiLine%


In the example above, the caret symbol (^) is used to concatenate multiple lines of strings and assign them to the variable “multiLine”. Then, the echo command is utilized to output the value of the variable. Finally, the endlocal command is used to end the code block and clear all local variables.

Running the above batch script will output the following results:

This is line 1.
This is line 2.
This is line 3.

Please note that the ^ symbol is not needed to connect the next line at the end of a string.

Leave a Reply 0

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