More or less, but if you know how and when delayed expansion works,
there aren't so many problems left.
Expanding a variable with delayed expansion is always absolutly safe,
independent of the content!
The cause is, that delayed expansion is the last phase of the parser,
and after the expansion the characters are not more examined by
anything.
But obviously the for-loop expansion of ex. %%a can't be also the last
phase.
So after expanding %%a the delayed expansion phase follows.
That causes the main problems.
But this can be avoided with toggling the delayed expansion
for /F "delims=" %%a in (myFile.txt) do (
set "line=%%a"
echo %%a - here is %%a safe
setlocal EnableDelayedExpansion
echo !line! This is absolutly safe
echo %%a This would fail if %%a contains exclamations marks, then
also carets are lost
endlocal
)
The delayed expansion phase has a special rule:
If at least one exclamation mark is present in the line carets are
escape characters for the next character,
but quotes haven't any effect in this phase.
This can be seen here
setlocal EnableDelayedExpansion
echo 1 ^^^^ "^^^^"
echo 2 ^^^^ "^^^^" .... !
echo 3 ^^! "^!"
Output
1 ^^ "^^^^"
2 ^ "^^" ....
3 ! "!"
Here you see that the carets are affected first in the "special
character phase" where "&|'()... are parsed.
As quotes are effectuve here, the line 1 will be modified to ^^ "^^^^"
As there isn't an exclamation mark the line will not more modified.
But line 2 has one so it will result to ^ "^^", now the carets also
work inside of quotes
jeb