Created
December 23, 2014 20:54
-
-
Save DavidLGoldberg/c386f9d770f2871ca9c7 to your computer and use it in GitHub Desktop.
Some Prompt stuff I used a few times...just keeping for reference.
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
#!/bin/bash | |
#Taken from: | |
#https://gist.github.com/1965569 | |
function ask { | |
while true; do | |
if [ "${2:-}" = "Y" ]; then | |
prompt="Y/n" | |
default=Y | |
elif [ "${2:-}" = "N" ]; then | |
prompt="y/N" | |
default=N | |
else | |
prompt="y/n" | |
default= | |
fi | |
# Ask the question | |
read -p "$1 [$prompt] " REPLY | |
# Default? | |
if [ -z "$REPLY" ]; then | |
REPLY=$default | |
fi | |
# Check if the reply is valid | |
case "$REPLY" in | |
Y*|y*) return 0 ;; | |
N*|n*) return 1 ;; | |
esac | |
done | |
} | |
commands=( | |
"echo 1" | |
"echo 2" | |
"echo 3" | |
); | |
for command in "${commands[@]}" | |
do | |
${command}; | |
if ask "proceed?" N; then | |
echo ; | |
else | |
echo "DEPLOYMENT ABORTED." | |
exit; | |
fi | |
done | |
echo "DEPLOYER COMPLETE." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment