My problem: I set a VAR with prompt and three IF to let choice. Fourth choice doesn't work. I would like that if i push enter without type anything, it goes back to :MOSTRA. Actually leaving it blank and typing enter on the keyboard it give back GOTO WAS UNEXPECTED and close CMD. Where am i wrong?
:MOSTRA
ECHO Make your choice.
ECHO.
ECHO A) Ok
ECHO B) Ko
ECHO Esci
SET /P choose=Scelta:
if /I %choose%==A GOTO OK
if /I %choose%==B GOTO KO
if /I %choose%==esci GOTO FINE
if /I %choose%=="" GOTO ERROR
:ERROR
ECHO You type nothing.
ECHO.
GOTO MOSTRA
:KO
ECHO Bad choice
ECHO.
GOTO MOSTRA
:OK
ECHO Right choice
ECHO.
GOTO MOSTRA
:FINE
exit
CMD will substitute the value of
choose
in the place of%choose%
sois interpreted as
which generates the error.
There is a more subtle error, too.
If you first choose
a
orb
, you get the "right choice" or "bad choice" response, correctly BUT if your next choice is simplyENTER
the response doesn't change - the previous response will be repeated.The reason is that
set /p
does not changechoose
if you simply typeENTER
. What you need iswhich sets
choose
to [nothing]