Created
May 20, 2019 08:06
-
-
Save AcckiyGerman/bbb8d635f1e6c4414c707f03ce7b2d1b to your computer and use it in GitHub Desktop.
yes or no dialog in bash
This file contains hidden or 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
read -p "Are you sure (y/n)? " -r | |
# $REPLY is where 'read' store user input by default | |
if [[ ! $REPLY =~ ^[Yy](es)*$ ]]; then | |
echo "Bye!"; exit 1; | |
fi | |
## loop-based variant: | |
while true; do | |
read -p "Do you want to start y/n? " yn | |
case $yn in | |
[Yy]* ) break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment