I've been working in Linux for the last 12 years, worked with Windows and command lines before that and have had to recently resurrect those batch file skills for a little easy to use / edit utility. However, I'm having some issues in finding out how to build up a string variable with newline characters (the equivalent of Linux's echo -e "Line1\nLine2")
Basically my utility asks three questions of a user and checks the validity of the inputs. Each input has a slightly different "error message" if the validity fails. I then have a check to see if the errMsg variable contains anything and if it does, it lists the collated error messages from the 3 validity checks. This all works perfectly with the exception of the error message is on one line and I'd like to put each error on it's own line. I then "merely" add newlines to the string ... and that's the crux of this question.
I've used this link as a reference point and with a basic string, the new lines appear as expected. However, when I use a variable, the new lines don't appear and I was hoping someone could explain to me why.
I have the following code snippet
@echo off
setlocal enableextensions enabledelayedexpansion
set \n=^
set NL=^^^%\n%%\n%^%\n%%\n%
echo This does indeed put in a newline%NL%and this is the 2nd line
:: output follows:
::This does indeed put in a newline
::and this is the 2nd line
set var=Line1%NL%
set var=%var%Line2%NL%
:: output follows:
::Line1Line2
set errMsg=This would be the first custom error message%NL%
set errMsg=%errMsg%This would be the second custom error message%NL%
set errMsg=%errMsg%This would be the third custom error message%NL%
:: output follows
::This would be the first custom error messageThis would be the third custom error message
Obviously at this point I was expecting the Line1Line2 example to be split across two lines, and then the last example to have all the custom error messages across three lines (whereas in reality, it's missing the 2nd / middle error message too)
Can anyone explain to me why this isn't working as expected? I'm wondering if it's related to the delayed expansion (which I believe I need: this snippet is part of a longer file that does need the delayed expansion). Is there a better (or merely alternative) way of completing what I'm looking for?!