Created
December 27, 2013 18:25
-
-
Save ezhuk/8150714 to your computer and use it in GitHub Desktop.
Ask the user to confirm an action.
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
#!/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