0

Ok, so I'm creating a simple batch file that's meant to get lines from a text file, then pipe the output to wget and download them (Using the Windows port). The only issue I'm having is adding a number to a number within the for loop.

SETLOCAL ENABLEDELAYEDEXPANSION
set sum=0
%ECHO% "Reading %1... "

for /f "eol=# tokens=* delims= " %%a in (%1) do ( 
    echo %%a | bin\wget -q %%a
    SET /a sum=%sum%+1
    echo Hit:%sum% %%a 
)

%ECHO% "Done!"
ENDLOCAL

It's being called like 'call read_line.bat myfile.txt

Yes, I know I could just use wget -i myfile.txt, but I'd prefer to not use that and have control on other things (Output, and The obvious HIT: function)

1 Answer 1

2

Try using ! instead of % for sum in order to really use delayed expansion:

for /f "eol=# tokens=* delims= " %%a in (%1) do ( 
  echo %%a | bin\wget -q %%a
  SET /a sum=!sum!+1
  echo Hit:!sum! %%a 
)
Sign up to request clarification or add additional context in comments.

1 Comment

You may also omit any expansion in SET /a command because it does not need it: SET /a sum=sum+1 or, better yet: SET /a sum+=1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.