2017-08-16 103 views
-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

+1

將'var'更改爲'set'。然後從最後一行刪除'!'或'%'。 – Compo

+0

@Compo,我更新了問題以澄清。謝謝! –

回答

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 

如果你想解釋你打算做什麼,而不是通過檢查你未能做什麼來確定你想要做什麼,那麼這將對你有所幫助。