This is not an XP issue. It is a "well known"
, but undocumented design feature of FOR /F.
If you want to include <space> in the list of DELIMS, the DELIMS option must be last in the list of options, and the <space> must be the last character of the list of DELIMS, followed immediately by the closing quote. The rule is so specific that even this example fails:
Code: Select all
for /f "tokens=1-2 delims=,<TAB><SPACE><SPACE>" %%a in (" this_fails 0 ") do echo.&echo.a=%%~a_&echo.b=%%~b_
Why? Since <space> is the option delimiter, any character after the <space> would be expected to be the beginning of the next option. The designers of FOR /F recognized the fact that <space> is an important possibility for DELIMS, so they wrote in special rules to allow <space> delimiter as long as it is the very last character of the entire list of options.
There is no design consistency.
The EOL option always takes the next single character after the = to be the "skip this line" character. If that next character happens to be <space>, then it also serves as the option delimiter. If it happens to be <double quote>, then it also serves as the end of options delimiter.
Code: Select all
for /f "eol=<space>delims=," %%a in (" no output because of eol") do echo %%a
for /f "eol=" %%a in ("" no output because of eol"") do echo %%a
I think it's a stupid design. I would have provided a mechanism to escape the <space> delimiter instead, as well as a mechanism to escape the escape. But we are stuck with what they gave us.
Dave Benham