Skip to content

Instantly share code, notes, and snippets.

@connoro7
Last active October 11, 2022 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save connoro7/3b9c356a69b8307dc53107692a87aec3 to your computer and use it in GitHub Desktop.
Save connoro7/3b9c356a69b8307dc53107692a87aec3 to your computer and use it in GitHub Desktop.
"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 with 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