I have the following block of code in my win2unix program:
Code: Select all
setlocal enabledelayedexpansion
if "%~1"=="" (if /i "!cmdcmdline!"=="!cmdcmdline:%~n0=!" (
endlocal & goto usage)) else (
if /i "!cmdcmdline!" neq "!cmdcmdline:%~n0=!" (
echo(specify input from EITHER pipe OR file--but not both 1>&2
endlocal & goto error))
endlocal
Delayed expansion is on, so I tried removing the quotes from the string comparisons and got a ") not expected at this time" error.
My suspicion fell on the GOTOs so I reformatted the code a little and ended up with:
Code: Select all
setlocal enabledelayedexpansion
if .%~1==. (if /i !cmdcmdline!==!cmdcmdline:%~n0=! (
endlocal & goto usage)
) else (
if /i !cmdcmdline! neq !cmdcmdline:%~n0=! (
echo(specify input from EITHER pipe OR file--but not both 1>&2
endlocal & goto error)
)
endlocal
And it worked!
My question is why does removing a few unnecessary quotes from string comparisons in delayed expansion make GOTO suddenly hypersensitive to the number of parentheses enclosing it? Is there no end to Batch's eccentric behaviour?
PS: Why aren't there smilies for "shameless plug" and "total bewilderment"? I'd put both of them to good use!