Reputation: 25
I want to check whether or not variable h="yes" or h="no" and my code is obviously incorrect. how could i fix it?
@echo what is your statement (YES/NO)?
set /p h=
if %h% EQ 'yes' goto YES
if %h% EQ 'no' goto NO
:YES
@echo you chose YES
pause > nul
goto END
:NO
@echo you chose NO
pause > nul
:END
Upvotes: 0
Views: 133
Reputation: 56208
just a little chages are neccessary:
@echo off
echo what is your statement (YES/NO)?
set /p h=
if /i '%h%' == 'yes' goto YES
if /i '%h%' == 'no' goto NO
echo wrong input
goto END
:YES
echo you chose YES
pause > nul
goto END
:NO
echo you chose NO
pause > nul
:END
if /i
makes it case-insensitive, so you can enter yes, YES, Yes or yEsUpvotes: 1
Reputation: 3519
I have been asked to whittle my response down.
I think this what you are looking for which is something like:
@ECHO OFF
CLS
CHOICE /C YN /M "DO YOU WANT TO RESTART APACHE TOMCAT WEB SERVICE?"
IF %ERRORLEVEL% == 2 GOTO END
ECHO DO OTHER STUFF HERE
:END
ECHO YOU PRESSED N OR SCRIPT HAS FINISHED
EXIT
Upvotes: 0