#!/bin/bash a=$1 #引数をaとする。 echo What"'"s your number? #”What's your number?"を表示する。 echo What"'"s your number? > quiz1.txt #quiz1.txtに”What's your number?"を書き込む echo b=? #”b=?”を表示する。 read b #入力する数字をbとして読み込む。 echo $b >> quiz1.txt #quiz1.txtにbの値を書き込む。 while test $a -ne $b; #a≠bである限り、doとdoneではさまれた部分を繰り返し実行する。 do if test $a -gt $b; then #もし「aがbよりも大きい」が真ならば echo Your number is smaller than the answer. #”Your number is smaller than the answer.”を表示する。 echo Your number is smaller than the answer. >> quiz1.txt #”Your number is smaller than the answer.”をquiz1.txtに書き込む。 echo b=? #”b=?”を表示する。 echo What"'"s your number? >> quiz1.txt #”What's your number?"をquiz1.txtに書き込む。 read b #入力する数字をbとして読み込む。 echo $b >> quiz1.txt #quiz1.txtにbの値を書き込む。 elif test $a -lt $b; then #もし「aがbよりも小さい」が真ならば echo Your number is larger than the answer. #”Your number is larger than the answer.”を表示する。 echo Your number is larger than the answer. >> quiz1.txt #”Your number is larger than the answer.”をquiz1.txtに書き込む。 echo b=? #”b=?”を表示する。 read b #入力する数字をbとして読み込む。 echo What"'"s your number? >> quiz1.txt #quiz1.txtに”What's your number?"を書き込む echo $b >> quiz1.txt #quiz1.txtにbの値を書き込む。 fi done echo Your number matches the answer "!!" #もし、a=bならば"Your number matches the answer!!"を表示する。 echo Your number matches the answer "!!" >> quiz1.txt #quiz1.txtに"Your number matches the answer!!"を書き込む。