Skip to content

Instantly share code, notes, and snippets.

@jhazelwo
Created March 25, 2017 18:22
Show Gist options
  • Save jhazelwo/0f516cee56ca44d5164def564f03d5e8 to your computer and use it in GitHub Desktop.
Save jhazelwo/0f516cee56ca44d5164def564f03d5e8 to your computer and use it in GitHub Desktop.
Example shell script to confirm, with optional override, before doing something destructive.
#!/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