Why is escaping exclamation marks not necessary in parameter of `for /F` or `for /R`?

The options of FOR, IF and REM are only parsed up to the special character phase.
Or better the commands are detected in the special character phase and a different parser is activated then.

Therefore it’s not possible to use delayed expansion nor FOR-Parameter in the options.

These tests fail with errors

for /F %%O in ("defined") do (
  if %%O var echo yes
)

set option=defined
if !option! var echo yes

This seems to work, but uses the wrong delimiters (D, e, i, l, m, s, y and ! )

set "myDelims=123"
for /F "tokens=1,2 delims=!myDelims!" %%A in ("Hello 1 world") do (
    echo Token1=%%A  Token2=%%B
)

And for REM

set "help=/?"
REM !HELP!  - No help will be shown

Leave a Comment