I\'m writing a simple script to substitute text in an environment variable with other text. The trouble I get is with the substituted or substituted text being pulled from o
Use CALL. Put the following in a batch script and run it:
set a=The fat cat
set b=fat
set c=thin
REM To replace "%b%" with "%c%" in "%a%", we can do:
call set a=%%a:%b%^=%c%%%
echo %a%
pause
As stated here, we use the fact that:
CALL internal_cmd
...
internal_cmd Run an internal command, first expanding any variables in the argument.
In our case internal_cmd is initially set a=%%a:%b%^=%c%%%.
After expansion internal_cmd becomes set a=%a:fat=thin%.
Thus, in our case running
call set a=%%a:%b%^=%c%%%
is equivalent to running:
set a=%a:fat=thin%.