传递多行字符串

传递多行字符串

问题描述:

我正在尝试创建一个批处理文件,该文件绕过带有换行符的字符串,但是无法正常工作.字符串的继续作为新命令执行.

I'm trying to create a batch file which passes around a string with line feeds in it but its not working out. The continuation of the string is executed as a new command.

反正有没有对换行进行编码或使之工作?

Is there anyway to encode a line feed or make this work?

您可以使用脱字符号直接创建多行字符串(需要一个空行).

You can create directly multiline strings with the caret (one empty line is required).

setlocal EnableDelayedExpansion
set multiLine=This is a ^

multiline text^

line3
echo !multiLine!

或者您可以先创建一个换行符.

Or you can create first a newline character.

setlocal EnableDelayedExpansion
set LF=^


rem Two empty lines are required
set multiLine=This is a!LF!multiline text!LF!line3
echo !multiLine!

有关其工作原理的解释,请参见解释dos-batch换行符变量hack的工作原理

An explanation how this works can be found at Explain how dos-batch newline variable hack works