问题
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