Wow jeb, I'm beginning to understand it
Thanks to dbenham,
I didn't know that you can disable the eol-character, if it is one of the delims-characters.
But I suppose I found a way to disable the eol even if the delims is empty.
Code:
setLocal EnableDelayedExpansion
set lf=^
for /F ^"eol^=^
delims^="" %%a in ("^^caret!lf!;semicolon!lf! space!lf!""quote") do echo '%%a'
It is obvious that the eol should be a <LF>, but as the FOR /F splits at each <LF>, it is the same as eol would be empty.
jeb
But you couldn't have found this by simply guessing, this requires insight !!!I've been sitting in front of DOS for over 15years & I never figured it out !
Still there's one thing I don't understand, why doesn't this simple test splits to a & b ?
Code: Select all
@echo off &setLocal EnableDelayedExpansion
for /F "delims=""" %%a in ("caret " " quote") do echo 'a=%%a' 'b=%%b'
for /F "delims="^" %%a in ("caret " " quote") do echo 'a=%%a' 'b=%%b'
pause
exit /b
It seems delims refuses to accept " as a valid delimiter ?!
Wow dBenham, what a clever variation
Code: Select all
@echo off
setlocal disableDelayedExpansion
set "str=skip 1st line,^caret,;semicolon, space,"quote,!exclamation"
setLocal EnableDelayedExpansion
set ^"str=!str:,=^
!"
echo str=!str!
echo:----------------
for /F ^"usebackq^ skip^=1^ eol^=^
delims^=^" %%a in ('!str!') do (
setlocal disableDelayedExpansion
echo '%%a'
endlocal
)
echo:---------------
setlocal disableDelayedExpansion
for /f ^"eol^=^
delims^=^" %%a in (";eol disabled so line preserved") do echo %%a
The fact that it's even possible
Ok dBenham now let's study your above post..... hmmm ... hmm ...
It is useful for building macros. It makes it convenient to build a macro with a FOR /F that is guaranteed to read the entire line (no eol, no delims).
dBenham, you know how long I've been looking for someting like this, I bet you were too
I just need to know one other thing, is it really bulletproof, have you tested this thoroughly with strings like:
" hjfjkfdfhj333""'" " " | | && || >> << ^^" " " " "8765 àç!è( "
I bet the quotes have to be even or it will still fail
So we still have to pre-prepare the input.
I am going to experiment with this...
" hjfjkfdfhj333""'" " " | | && || >> << ^^" " " " "8765 àç!è( "
Whaa that didn't work, I'm always way to optemistic. Only a fool like me would try this.
@dBenham Euh, I guess you are already trained at this, do you know of a variation for EnabledDelayedExpansion