Created
September 30, 2012 16:05
-
-
Save usaturn/3807271 to your computer and use it in GitHub Desktop.
シェルスクリプトで再帰とwhile文
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
#!/bin/bash | |
function yes_or_no_recursive(){ | |
echo | |
echo "Type yes or no." | |
read answer | |
case $answer in | |
yes) | |
echo -e "tyeped yes.\n" | |
return 0 | |
;; | |
no) | |
echo -e "tyeped no.\n" | |
return 1 | |
;; | |
*) | |
echo -e "cannot understand $answer.\n" | |
yes_or_no_recursive | |
;; | |
esac | |
} | |
yes_or_no_recursive | |
function yes_or_no_while(){ | |
while true;do | |
echo | |
echo "Type yes or no." | |
read answer | |
case $answer in | |
yes) | |
echo -e "tyeped yes.\n" | |
return 0 | |
;; | |
no) | |
echo -e "tyeped no.\n" | |
return 1 | |
;; | |
*) | |
echo -e "cannot understand $answer.\n" | |
;; | |
esac | |
done | |
} | |
yes_or_no_while | |
#function yes_or_no_select(){ | |
# PS3="Answer? " | |
# while true;do | |
# echo "Type 1 or 2." | |
# select answer in yes no;do | |
# case $answer in | |
# yes) | |
# echo -e "tyeped yes.\n" | |
# return 0 | |
# ;; | |
# no) | |
# echo -e "tyeped no.\n" | |
# return 1 | |
# ;; | |
# *) | |
# echo -e "cannot understand your answer.\n" | |
# ;; | |
# esac | |
# done | |
# done | |
#} | |
# | |
#yes_or_no_select |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment