Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rroemhild
Created June 1, 2012 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rroemhild/2855383 to your computer and use it in GitHub Desktop.
Save rroemhild/2855383 to your computer and use it in GitHub Desktop.
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