Using the Windows XP CMD command-line I can expand a variable twice as follows:
set AAA=BBB
set BBB=CCC
for /F \"usebackq tokens=*\" %i in (`echo %%AAA%%`) d
How to expand a shell variable multiple times:
@echo off
setlocal enabledelayedexpansion
set myvar=second
set second=third
set third=fourth
set fourth=fifth
echo Variable value before expansion: !myvar!
call :expand myvar
echo Variable value after expansion: !myvar!
goto :eof
:expand
set var=%1
:expand_loop
if not "!%var%!" == "" (
set var=!%var%!
goto :expand_loop
)
set %1=!var!
goto :eof
output:
Variable value before expansion: second
Variable value after expansion: fifth