Insert line break/special character in string in command line
Solution 1:
The txtechhelp's advice is close:
==> set a=dupa;jasiu;karuzela;
==> echo %a:;=&echo.%
dupa
jasiu
karuzela
==>
However, you need to escape the &
ampersand character in a set
command using either the general escape character (^
caret):
==> set b=%a:;=^&echo.%
==> echo %b%
dupa
jasiu
karuzela
or using double quotes:
==> set "c=%a:;=&echo.%"
==> echo %c%
dupa
jasiu
karuzela
You could loop over the %a%
variable in a for
loop.
It's simple if %a%
does not contain other delimiter(s) like space, tab, comma or equals sign:
==> for %f in (%a%) do @echo %f
dupa
jasiu
karuzela
==>
Otherwise, if %a%
contains some other delimiter(s) like space, tab, comma or equals sign:
==> set a=dupa;jasiu;karu zela;
==> for %f in (%a%) do @echo %f
dupa
jasiu
karu
zela
==> for %f in ("%a:;=";"%") do @if not "%~f"=="" echo.%~f
dupa
jasiu
karu zela
==>
Please note the %f
loop parameter (above examples copied & pasted from an open cmd
command window).
In a batch file, denominate it properly using doubled percent sign as %%f
:
for %%f in (%a%) do echo %%f