Skip to content

Instantly share code, notes, and snippets.

@sroccaserra
Created September 8, 2014 08:23
Show Gist options
  • Save sroccaserra/795099687386ff10d35c to your computer and use it in GitHub Desktop.
Save sroccaserra/795099687386ff10d35c to your computer and use it in GitHub Desktop.
Bash prompt for dangerous tasks
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