Last active
October 11, 2022 18:28
-
-
Save connoro7/3b9c356a69b8307dc53107692a87aec3 to your computer and use it in GitHub Desktop.
"Confirm Action" Shell Function
This file contains 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
# 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