- Oct
- 1
- 0
In a loop parsing arguments, when the condition of a IF is false, make it exit.
Here is a very simplified example that show the bug (bug.bat) :
Here is the console output, with the condition evaluated to TRUE :
And now, with the condition evaluated to FALSE :
If looks like the IF FALSE acts like an exit from the loop...
By the way, the same batch executed by MS cmd runs as expected :
Here is a very simplified example that show the bug (bug.bat) :
Bash:
set args=spam and eggs
:loop
for /F "tokens=1,* delims= " %%a in ("%args%") do (
echo ------------------- "%%a" / "%%b"
if "%1" == "1" echo within if
echo after if
set args=%%b
goto :loop
)
Here is the console output, with the condition evaluated to TRUE :
Code:
TCC>bug.bat 1
------------------- "spam" / "and eggs"
within if
after if
------------------- "and" / "eggs"
within if
after if
------------------- "eggs" / ""
within if
after if
Code:
TCC>bug.bat 2
------------------- "spam" / "and eggs"
If looks like the IF FALSE acts like an exit from the loop...
By the way, the same batch executed by MS cmd runs as expected :
Code:
CMD>bug.bat 2
------------------- "spam" / "and eggs"
after if
------------------- "and" / "eggs"
after if
------------------- "eggs" / ""
after if