How can I echo a string in a %Isafe manner, regardless of whether the string is echoin a loop for %I?
For example, on the command line ( cmd):
>>> rem // `echo` is outside of `for` scope, so this works:
>>> echo %I
%I
>>> rem // `echo` is inside of `for` scope, so `%I` is resolved:
>>> for %I in (.) do @echo %I
.
>>> rem // escaping does not help, `%I` is still resolved:
>>> for %I in (.) do @(echo ^%I & echo %^I & echo ^%^I & echo %%I)
.
.
.
%.
And in the batch file ...:
@echo off & rem // Here you need to double the `%` signs!
rem // `echo` is outside of `for` scope, so this works:
echo %%I & echo %%%%I
echo/
rem // `echo` is inside of `for` scope, so `%%I` is resolved:
for %%I in (.) do (echo %%I & echo %%%%I)
echo/
rem // escaping does not help, `%%I` is still resolved:
for %%I in (.) do (echo ^%%I & echo %%^I & echo ^%%^I & echo ^%^%I & echo ^%^%^I & echo ^%%^%%^I)
... result:
%I
%%I
.
%.
.
.
.
I
^I
%.
So, how do I modify the above approaches (both the cmdbatch file) to get an %Iecho?
source
share