Advertisement
cd62131

Yes or No Loop

Aug 6th, 2017
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.39 KB | None | 0 0
  1. #!/bin/bash
  2. shopt -s nocasematch
  3.  
  4. yes_or_no() {
  5.   prompt=$1
  6.   read -pr "${prompt}" answer
  7.   case ${answer} in
  8.     yes) return 0 ;;
  9.     no) return 1 ;;
  10.     *) yes_or_no "yesかnoで入力: " ;;
  11.   esac
  12. }
  13.  
  14. typeset -i busyday=0
  15. for week in 月 火 水 木 金 土 日; do
  16.   yes_or_no "${week}曜日は?(yes/no) " && (( busyday++ ))
  17. done
  18.  
  19. echo "忙しいのは${busyday}日だった"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement