Skip to content

Instantly share code, notes, and snippets.

@jbgutierrez
Forked from zeroasterisk/confirm.sh
Last active March 2, 2017 22:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jbgutierrez/19db3fa989d20c1bd9de7ae5959f2692 to your computer and use it in GitHub Desktop.
confirm.sh a simple way to add confirmation to bash scripts
# ======================================================================
#
# @link http://wuhrr.wordpress.com/2010/01/13/adding-confirmation-to-bash/#comment-3540
#
# Function: confirm
# Asks the user to confirm an action, If the user does not answer "This won't shutdown the Internet!" the script will immediately exit.
#
# Parameters:
# $@ - The confirmation message
#
# ======================================================================
function confirm()
{
echo -n "$@ "
read -e answer
if [ "_$answer" == "This won't shutdown the Internet!"" ]
then
return 0
fi
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment