批处理文件将多个变量编程为一个变量

时间:2013-11-08 05:13:55

标签: batch-file batch-processing

可以做这样的事吗?

@echo off
setlocal enabledelayedexpansion
set 1=one
set 3=three
set onetwothree=output
echo !%1%two%3%!
pause

其中变量%1%将变为1,变量%3%将变为最后一个变量中的三个,然后%onetwothree%将回显为onetwothree输出设置的内容?

1 个答案:

答案 0 :(得分:2)

虽然这个想法是正确的,但这不起作用,因为1不能用作变量名。这是因为%1%被解释为第一个参数%1后跟百分号的值。只需更改这些变量的名称:

@echo off
setlocal enabledelayedexpansion
set A1=one
set A3=three
set onetwothree=output
echo !%A1%two%A3%!
pause