Last active
November 4, 2016 08:44
-
-
Save cpelley/b0c68de930bdea4f9f93a3677df0b44a to your computer and use it in GitHub Desktop.
Commandline utility to request confirmation before running a command.
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/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