Last active
August 21, 2017 02:28
-
-
Save seangeleno/2ffa4167ff0988f9cd3253953da24a47 to your computer and use it in GitHub Desktop.
Prompt User
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
# (1) prompt user, and read command line argument | |
read -p "Run the cron script now? " answer | |
# (2) handle the command line argument we were given | |
while true | |
do | |
case $answer in | |
[yY]* ) /usr/bin/wget -O - -q -t 1 http://www.example.com/cron.php | |
echo "Okay, just ran the cron script." | |
break;; | |
[nN]* ) exit;; | |
* ) echo "Dude, just enter Y or N, please."; break ;; | |
esac | |
done |
second version stays in a loop until the user supplies a Y/N answer:
while true
do
# (1) prompt user, and read command line argument
read -p "Run the cron script now? " answer
# (2) handle the input we were given
case $answer in
[yY]* ) /usr/bin/wget -O - -q -t 1 http://www.example.com/cron.php
echo "Okay, just ran the cron script."
break;;
[nN]* ) exit;;
* ) echo "Dude, just enter Y or N, please.";;
esac
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This first version prompts the user for input only once, and then dies if the user doesn't give a correct Y/N answer: