2014-02-18 82 views
0
如何

獲得使這個循環的工作:For循環在Windows命令行

set list=am gp it ol 

FOR %%a IN (%list%) DO ( 
    set Indxed= %%a 
    ECHO %Indxed%    

) 

回聲總是輸出到:醇醇醇醇。我該如何解決這個問題?

回答

0

嘗試以下操作:

@echo off 
setlocal 

set list=am gp it ol 

echo %list% 

call :parse "%list%" 

goto :eos 

:parse 

set list=%1 
set list=%list:"=% 

FOR /f "tokens=1* delims= " %%a IN ("%list%") DO (
    if not "%%a" == "" call :sub %%a 
    if not "%%b" == "" call :parse "%%b" 
) 

goto :eos 

:sub 

echo %1 

goto :eos 

:eos 
endlocal 
1

測試此:

@echo off 
setlocal enabledelayedexpansion 

set list=am gp it ol 

FOR /f "delims=" %%a IN ("%list%") DO (
    set Indxed=%%a 
    ECHO !Indxed! 
)