Reputation: 786
if "x%1" == "x" (
goto :l2
)
:l2
echo doskey %1>>startup.cmd
Tried with and without parentheses on both the condition and the goto, also tried without quotation marks and of course goto on the same line - it always returns true.
Upvotes: 2
Views: 9109
Reputation: 130819
You have a very silly error :-)
If the condition is true you GOTO the label.
If the condition is false you don't GOTO, but you fall through to the next line which happens to be your label.
Same result either way!
Other issues -
1) I think your logic is reversed. I believe you only want to GOTO :l2 if %1 is defined, you have the reverse.
2) A %1 value of "A&B"
(including quotes) would fail. Better to use "%~1"
instead of "%1"
3) There is no need for the x in your comparison.
Easily fixed:
if "%~1" neq "" goto :l2
exit /b
:l2
echo doskey %1>>startup.cmd
You really don't need the goto:
if "%~1" neq "" echo doskey %1>>startup.cmd
Upvotes: 7