Created
June 9, 2024 10:25
-
-
Save okurka12/289dfbcef6f835cb3526ea527983bfe4 to your computer and use it in GitHub Desktop.
utilities for POSIX shell
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
# ask if something is ok, exit if it's not | |
# if OPTION_Y variable is "-y", do nothing | |
prompt_confirm () { | |
if [ "$OPTION_Y" != "-y" ]; then | |
printf "%s (y/n) " "$*" | |
read -r PROCEED | |
if [ "$PROCEED" != "y" ]; then | |
echo "abort" | |
exit | |
fi | |
fi | |
} | |
# if $1 exists, ask if its ok to delete and then delete | |
safe_delete () { | |
if [ -f "$1" ]; then | |
prompt_confirm "delete $1?" | |
echo "deleting $1" | |
rm "$1" | |
fi | |
} | |
# if $1 exists, ask if its ok to overwrite | |
ask_overwrite () { | |
if [ -f "$1" ]; then | |
prompt_confirm "overwrite $1?" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment