Skip to content

Instantly share code, notes, and snippets.

@AcckiyGerman
Created May 20, 2019 08:06
Show Gist options
  • Save AcckiyGerman/bbb8d635f1e6c4414c707f03ce7b2d1b to your computer and use it in GitHub Desktop.
Save AcckiyGerman/bbb8d635f1e6c4414c707f03ce7b2d1b to your computer and use it in GitHub Desktop.
yes or no dialog in bash
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