Skip to content

Instantly share code, notes, and snippets.

@cpelley
Last active November 4, 2016 08:44
Show Gist options
  • Save cpelley/b0c68de930bdea4f9f93a3677df0b44a to your computer and use it in GitHub Desktop.
Save cpelley/b0c68de930bdea4f9f93a3677df0b44a to your computer and use it in GitHub Desktop.
Commandline utility to request confirmation before running a command.
#!/bin/sh
# Function to verify user want to run the commant.
#
# Add this file to your PATH to make available and ensure that it has
# executable privileges.
#
# Example usage:
# confirm && <command>
# http://stackoverflow.com/questions/3231804/in-bash-how-to-add-are-you-sure-y-n-to-any-command-or-alias
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment