![]() |
Passing around multi-line strings - Printable Version +- 0Day Forums (https://0day.red) +-- Forum: Coding (https://0day.red/Forum-Coding) +--- Forum: .bat & .wsf & .cmd (https://0day.red/Forum-bat-wsf-cmd) +--- Thread: Passing around multi-line strings (/Thread-Passing-around-multi-line-strings) |
Passing around multi-line strings - spinrad15069 - 07-23-2023 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? RE: Passing around multi-line strings - lipaciduria210881 - 07-23-2023 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][2] [2]: [To see links please register here] RE: Passing around multi-line strings - Sirdendron762 - 07-23-2023 Expansion to [jeb answer][1] , Adding !LF!^ to each line would be easy setlocal EnableDelayedExpansion set LF=^ set multiLine=This is a!LF!^ multiline text!LF!^ line3 echo !multiLine! [1]: [To see links please register here] |