Skip to content

Instantly share code, notes, and snippets.

@ezhuk
Created December 27, 2013 18:25
Show Gist options
  • Save ezhuk/8150714 to your computer and use it in GitHub Desktop.
Save ezhuk/8150714 to your computer and use it in GitHub Desktop.
Ask the user to confirm an action.
#!/bin/bash
#
# This function asks the user to confirm an action with No used as a default
# answer.
confirm()
{
while true; do
read -p "$1" RES
case "$RES" in
Y|y) return 0 ;;
N|n|"") return 1 ;;
esac
done
}
# Example usage.
if confirm "Do you want to do something? [y/N]: "; then
# Yes, do that.
else
# No, don't do that.
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment