Reputation: 3
I am very much a newb at batch programming, but I can't seem to find an answer that fixes my problem. Any time I include a set /p
command into my batch file, inputting anything that includes a space between letters instantly closes the program.
Here's the code in question:
set /p action=">>"
if not defined action goto nothing
if /i %action% equ fight goto fight
if /i %action% equ magic goto magic
if /i %action% equ heal goto heal
if /i %action% equ "do nothing" goto nothing
goto battscr
I'm obviously trying to create a response to the input, "do nothing", but every time a user types a space between characters, immediately after pressing enter it will close. Running the batch through cmd gives the error "nothing was unexpected at this time." with "nothing" referring to the input after the space.
Upvotes: 0
Views: 678
Reputation: 38623
Use either this syntax:
IF /I "%VARIABLE%" EQU "STRING" GOTO LABEL
Or preferably this:
IF /I "%VARIABLE%"=="STRING" GOTO LABEL
The double quotes are included in the comparison.
Upvotes: 3