I have a very simple batch script:
@echo off
if %1 == a goto AA
if %1 == b goto BB
goto end
:AA
echo a
goto end
:BB
echo b
goto end
:END
echo on
If I call it with an argument test.bat a, I get what I expected, but if I call it without any arguments test.bat, I get goto was unexpected at this time. and the offending line is if %1 == a goto AA.
Why?
this line
if %1 == a goto AAwill becomeif == a goto AAwhen there are no arguments.if you use
if .%1 == .a goto AAthen the line becomesif . == .a goto AAwith no arguments, and windows does not throw an error of having nothing betweenifand==