Skip to content

Instantly share code, notes, and snippets.

@DavidLGoldberg
Created December 23, 2014 20:54
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 DavidLGoldberg/c386f9d770f2871ca9c7 to your computer and use it in GitHub Desktop.
Save DavidLGoldberg/c386f9d770f2871ca9c7 to your computer and use it in GitHub Desktop.
Some Prompt stuff I used a few times...just keeping for reference.
#!/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