Windows Batch Variable within variable

后端 未结 3 1606
夕颜
夕颜 2020-12-11 08:01

In windows batch could you set a variable within a variable?

Explained:

So the %num% is within the variable.

set num=5
set cnum=test
set h1=%         


        
3条回答
  •  孤城傲影
    2020-12-11 08:47

    Are you after something like this?

    cls
    @echo off
    setlocal EnableDelayedExpansion
    Set num=5
    Set "c!num!=test"
    Echo !c5!
    

    See http://ss64.com/nt/delayedexpansion.html for more info on delayed expansion.

    cls
    @echo off
    setlocal EnableDelayedExpansion
    set num=4
    set c1=this is a demo
    set c2=second example
    set c3=third
    set c4=this is the one I want
    set c5=last
    Echo !c%num%!
    

提交回复
热议问题