如何使用批处理脚本在变量内设置变量?

How do I set a variable inside a variable using batch script?

提问人:user20194509 提问时间:11/22/2022 最后编辑:Compouser20194509 更新时间:11/23/2022 访问量:34

问:

我想创建一个指向随机 url 的脚本(英语、法语和西班牙语,只是 url 结尾的示例,而不是实际的 url)。可能有更好的方法来设置变量,但由于代码其余部分的设置方式,我需要它以这种特定方式设置。

REM define list entries
set list[0]=english
set list[1]=french
set list[2]=spanish

REM create a random number, smaller than the list's length
set /a randomNum=(%RANDOM%*3/32768)
start "" http://youtube.com/%list[%randomNum%]%

这转到 ,而不是我设置的变量的值。youtube.com/randomNum

有什么帮助让它去等吗?youtube.com/english

Windows 批处理文件 变量 cmd

评论

0赞 Compo 11/23/2022
三个词供你研究:延迟变量扩展。
0赞 Qwerty 11/23/2022
此页面可能对您有帮助:EnableDelayedExpansion
0赞 JosefZ 11/23/2022
call start "" http://youtube.com/%%list[%randomNum%]%%高级用法:调用内部命令中进行了描述。
0赞 Aacini 11/24/2022
在启用延迟扩展的情况下使用,请参阅:arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-scriptstart "" http://youtube.com/!list[%randomNum%]!

答: 暂无答案