Created
August 15, 2014 22:33
-
-
Save jcefoli/fb9400aafee2ac585db3 to your computer and use it in GitHub Desktop.
Template for Yes/No Choice input in batch files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
:start | |
SET choice= | |
SET /p choice=Do something? [N]: | |
IF NOT '%choice%'=='' SET choice=%choice:~0,1% | |
IF '%choice%'=='Y' GOTO yes | |
IF '%choice%'=='y' GOTO yes | |
IF '%choice%'=='N' GOTO no | |
IF '%choice%'=='n' GOTO no | |
IF '%choice%'=='' GOTO no | |
ECHO "%choice%" is not valid | |
ECHO. | |
GOTO start | |
:no | |
ECHO Do all of the no things here! | |
PAUSE | |
EXIT | |
:yes | |
ECHO Do all of the yes things here! | |
PAUSE | |
EXIT |
Minor fixes this:
IF '%choice%'=='Y' GOTO yes
IF '%choice%'=='y' GOTO yes
Replace with this:
IF /i '%choice%'=='Y' GOTO yes
It supports uppercase and lowercase text input
Minor fixes this:
IF '%choice%'=='Y' GOTO yes IF '%choice%'=='y' GOTO yes
Replace with this:
IF /i '%choice%'=='Y' GOTO yes
It supports uppercase and lowercase text input
This may depend on OS (???) because on my machine, this input is case-sensitive (meaning that you need both the upper- and lowercase options or else one will be read as an invalid input). I'm on Windows 10, running in console.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, you are correct. I misread that. I was thinking he meant if they just hit "Enter" without putting in a selection, it would just take them to the "yes" block.