Skip to content

Instantly share code, notes, and snippets.

@connoro7
Created Oct 23, 2020
Embed
What would you like to do?
"Confirm Action" Shell Function
# Usage: Command line user-error reduction and fail-safe utility
function confirm()
{
# alert the user what they are about to do.
# echo "About to $@....";
# confirm with the user
read -r -n 1 -p "$Yellow>Are you sure? [y/N]: $Color_Off" response
case "$response" in
[yY][eE][sS]|[yY])
# if yes, then execute the passed parameters
# "$@" # comment out to disable this function from passing it's own commands, to force syntax "confirm && <COMMAND>"
echo -e ""
;;
*)
# Otherwise exit...
echo -e "\nAborting..."
return 1 2>/dev/null
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment