3

I have a problem about variable in variable ( the code is below ) :

set a=1
set b=a
echo %%b%%

The expected result is :

1

As a is assigned to variable b and 1 is assigned to variable a.

Also, there is another situation :

set b=a
set a1=100
set c=1
call set d=%a%c%%
echo %d%

I want the program to first turn %c% to 1 and then turn %a1% to 100.
The expected output is 100.

What is the simplest way to complete this task?

Jamie
  • 1,096
  • 2
  • 19
  • 38

2 Answers2

6
set a=1
set b=a
call echo %%%b%%%

And this will work faster:

@echo off
set a=1
set b=a
setlocal enableDelayedExpansion
echo !%b%!
endlocal

And just in case you need to do this within brackets context (e.g. if , for ...) :

@echo off
set a=1
set b=a
setlocal enableDelayedExpansion
(
 for /f %%v in ("%b%") do echo !%%~v!
)
endlocal
npocmaka
  • 55,367
  • 18
  • 148
  • 187
1

like for the variable x%abc%,

echo x%abc%>a.a
set /p temp=<a.a
call echo %%temp%%>a.a
set /p temp=<a.a
set temp

That's all!

Tool Box
  • 71
  • 11