How to change the name of an environment variable with a different variable?

喜欢而已 提交于 2020-01-06 07:28:29

问题


Is there a method to name an environment variable dynamically using another environment variable in a batch file?

Something like

numplayers=3
char%numplayer%atk=12 
echo char3atk  

with output

12

回答1:


It's quite straightforward:

SET numplayers=3
SET char%numplayers%atk=12
ECHO %char3atk%



回答2:


Given that you are unlikely to know beforehand the number assigned to %numplayers%, here are a few ways you can see the value of the variable:

Set "numplayers=3"
Set "char%numplayers%atk=12"
Call Echo %%char%numplayers%atk%%

 

Set "numplayers=3"
Set "char%numplayers%atk=12"
Set char%numplayers%atk

 

SetLocal EnableDelayedExpansion
Set "numplayers=3"
Set "char%numplayers%atk=12"
Echo !char%numplayers%atk!


来源:https://stackoverflow.com/questions/49984527/how-to-change-the-name-of-an-environment-variable-with-a-different-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!