Cmd - get variable in variable name

前端 未结 2 415
傲寒
傲寒 2021-01-21 04:57

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

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

The expected result is :

         


        
相关标签:
2条回答
  • 2021-01-21 05:25

    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!

    0 讨论(0)
  • 2021-01-21 05:35
    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
    
    0 讨论(0)
提交回复
热议问题