[英]Batch, variable inside variable in a for loop
How to set a variable inside a variable in a for loop? 如何在for循环中的变量内设置变量? When I execute this code the var[] is empty.
当我执行此代码时,var []为空。 Someone can help me?
有人可以帮我吗?
@echo off & setlocal enabledelayedexpansion
set var[0]=aaa
set var[1]=bbb
set var[2]=ccc
set var[3]=ddd
set var[4]=eee
for /L %%g in (1,1,3) do (
set /a num=!RANDOM! %% 5
echo position: !num!
echo keyword: !var[%num%]! :: THIS LINE NOT WORKING
)
pause
You essentially have two options to get the double variable expansion you require. 本质上,您有两种选择来获得所需的双变量扩展。 You can either use
CALL
or another FOR
command. 您可以使用
CALL
或另一个FOR
命令。
call echo keyword: %%var[!num!]%%
or 要么
FOR %%h in (!num!) do echo keyword: !var[%%h]!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.