Created
March 25, 2017 18:22
-
-
Save jhazelwo/0f516cee56ca44d5164def564f03d5e8 to your computer and use it in GitHub Desktop.
Example shell script to confirm, with optional override, before doing something destructive.
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 | |
# | |
# confirm_delete.sh - Example shell script to confirm, with optional override, before doing something destructive. | |
# | |
removeit() { | |
# Code that does something destructive. | |
exit 0 | |
} | |
if [ "$1" = "--force" ]; then | |
removeit | |
fi | |
while : ; do | |
read -p "Are you sure want to do this? [y/N] " this | |
case "${this}" in | |
Y|n ) removeit;; | |
N|n|'' ) exit 0;; | |
* ) echo "Y or N";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment