Skip to content

Instantly share code, notes, and snippets.

@usaturn
Created September 30, 2012 16:05
Show Gist options
  • Save usaturn/3807271 to your computer and use it in GitHub Desktop.
Save usaturn/3807271 to your computer and use it in GitHub Desktop.
シェルスクリプトで再帰とwhile文
#!/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