变量外部for / f命令不断重置

时间:2017-11-24 19:15:05

标签: batch-file

在下面的代码中,每次执行set /A lcnt=3下方的for / f命令时,似乎都会执行文件顶部的REM #1

我想我不明白执行的流程。我认为它只是从上到下运行,除非有任何结果。

我的剧本:

echo off

REm     Why is the following set command executed each time
REM     in the below "processToken section"? 

set /A lcnt=3

cd c:\download

REM         ___ input file _____
REm         Moe Larry Curly 
REM         Manny Moe Jack 

REM         ___ echo output ____
REM         4
REM         3
REM         5
REM         4
REM         6
REM         5
REM         4
REM         3
REM         5
REM         4
REM         6
REM         5

REm #1

for /f "tokens=* delims= " %%f in ('type test_list.txt') do (
  set line=%%f
  call :processToken
   )
pause
  goto :eof

:processToken
  SETLOCAL EnableDelayedExpansion 
  for /f "tokens=1* delims= " %%a in ("%line%") do (
    set /A lcnt+=1

    echo !lcnt!
    echo %lcnt% 

    set line=%%b
  )
  if not "%line%" == "" goto :processToken
  goto :eof

pause   

0 个答案:

没有答案