If so How?
Yes, batch files are lame, but I cannot use powershell, and I don\'t feel like writing a real app to do this simple task....
edit
I think I figured it out. I had to add ^
to the %NL%
var when putting it in the string, otherwise it hides the text after the first %NL%
because its executing when being set, instead of when its being echoed later
set NL=^& echo
set str=text on line 1 ^%NL% text on line 2
echo %str%
text on line 1
text on line 2
This is a pretty old question, but I put together a hybrid of the solutions from @Fabricio and @jeb that both worked correctly and added some readability:
setlocal enableDelayedExpansion
set NL=^
rem two empty line required
set var=this is a !NL! ^
multi !NL! ^
line !NL! ^
string !NL!
echo !var!
SET myFlags= ^
a ^
b ^
c
Or you can create a "real" newline character.
setlocal enableDelayedExpansion
set NL=^
rem two empty line required
echo first line !NL! second line
set multi=Line1!NL!Line2
set multi=!multi!!NL!Line3
echo !Multi!
With this variant the newline is a "normal" character in the string, so the variables act normally and you can assign them to another variable, this is not possible with the &echo.
trick (which is useful for simple tasks).
If you just wanted to use it for outputting the lines of variables, I hope this would be useful to you.
Inspired by something, I found this working.
For codes in normal Command Prompt:
set this=echo hi ^& echo bye
%this%
It gives out the two following two lines:
hi
bye
in the Command Prompt window.
The reason for using the ^
character:
Command Prompt would identify that you wanted to run two commands so that you need to add this character, that tells Command Prompt to recognize the next character as a symbol and not to do any special thing for it.
And now - without auxiliary SET commands:
echo this is a & echo multi & echo line & echo string