Created
September 8, 2014 08:23
-
-
Save sroccaserra/795099687386ff10d35c to your computer and use it in GitHub Desktop.
Bash prompt for dangerous tasks
This file contains 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
function ask_yes_or_no() { | |
read -p "$1 ([y]es or [N]o): " | |
case $(echo $REPLY | tr '[A-Z]' '[a-z]') in | |
y|yes) echo "yes" ;; | |
*) echo "no" ;; | |
esac | |
} | |
# And an example using it: | |
if [[ "no" == $(ask_yes_or_no "Are you sure?") || \ | |
"no" == $(ask_yes_or_no "Are you *really* sure?") ]] | |
then | |
echo "Skipped." | |
exit 0 | |
fi | |
# Then do something really dangerous... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment