Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
query yes no
query_yesno () {
DEFAULT="no"
YES="y"
NO="n"
case $2 in
[Yy]*) YES="Y"
DEFAULT="yes";;
[Nn]*) NO="N"
DEFAULT="no";;
esac
while true; do
read -p "$1 [$YES/$NO]: " yn
if [ "$yn" = "" -a "$2" != "" ]; then
yn=$2
elif [ "$yn" = "" ]; then
yn=$DEFAULT
fi
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) 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