How to set a variable equal to the contents of another variable?

允我心安 提交于 2019-12-10 09:31:34

问题


In the following (simplified example) batch file I am having difficulty correctly setting Y:

@Echo off
setlocalenabledelayed Expansion
set EqS=Nope
set X=Eq
set Y=%X%S 
echo Y

How can I get the output of this script to be Nope instead of EqS?


回答1:


As Karl ask, there could be different meanings of your question.
I try to give an answer for each possibility

@echo off
setlocal EnableDelayedExpansion
set EqS=Nope
set X=Eq

REM set Y1 to "EqS" 
set Y1=%X%S 

REM set Y2 to "Nope" (content of EqS)
set Y2=!%X%S!

REM set Y3 to "!EqS!"
set Y3=^^!%X%S^^!

echo %Y1%
echo %Y2%
echo %Y3%
set EqS=Something
echo(
echo Text %Y1%
echo Content %Y2%
echo Pointer %Y3%


来源:https://stackoverflow.com/questions/8363019/how-to-set-a-variable-equal-to-the-contents-of-another-variable

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