-1

我有:

setlocal EnableDelayedExpansion
var inLoopVar=hey
var first=!inLoopVar!
echo %!first!%

这输出ECHO OFF因为%!first!%返回为空。

如何打印“嘿”

更新和澄清:

这是我的完整代码,并评论了我正在尝试做的事情

@ECHO OFF
setlocal EnableDelayedExpansion
set RESULT=TRUE
set INPUT[0]=+NAME=RESULT; VARB=Second; VARC=Second; VARD=Second; VARE=Second; VARF=Second; VARG=Second;
set length=1
set i=0
:loop
if %i% equ %length% goto :eof
for /f "usebackq delims=+ tokens=2" %%j in (`set INPUT[%i%]`) do (
    set y=%%j
    FOR /f "tokens=1-7 delims=; " %%a IN ("!y!") DO (
       set aaa=%%a
       set testVar=!aaa:~5!
       REM basically testVar resolves to RESULT
       echo !!testVar!!
       REM Above echo prints "RESULT"
       echo %!!testVar!!%
       REM Above echo prints "ECHO is off."
    )
)
set /a i=%i%+1
goto loop

而不是ECHO is off.我试图输出TRUE

4

1 回答 1

0
@ECHO OFF
setlocal EnableDelayedExpansion
set RESULT=TRUE
set INPUT[0]=+NAME=RESULT; VARB=Second; VARC=Second; VARD=Second; VARE=Second; VARF=Second; VARG=Second;
set length=1
set i=0
:loop
if %i% equ %length% goto :eof
for /f "usebackq delims=+ tokens=2" %%j in (`set INPUT[%i%]`) do (
    CALL :sub %%j
)
set /a i=%i%+1
goto loop
GOTO :EOF

:sub
SET "namepart="
FOR %%a IN (%*) DO IF DEFINED namepart (
 SET "Valuepart=!%%a!"
 ECHO !namepart! is !valuepart!
 SET "namepart="
) ELSE (
 SET "namepart=%%a"
)
GOTO :eof

如果你能解释你打算做什么,而不是通过检查你是如何没有做任何事情来确定你想做的事情,这将有所帮助。

于 2017-08-16T17:06:13.473 回答