Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

windows - Passing around multi-line strings

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...