#!/bin/bash echo "What's your number?" | tee quiz1.txt read a #What's your number?と表示して、quiz1.txtに書き込み、入力された数をaとして読み込む。 echo "$a" >> quiz1.txt #quiz1.txtに入力された数aを書き込む。 while [ $a -ne $1 ] do #答えの数と入力した数が等しくなければ、以下を実行する。 if [ $a -gt $1 ] then echo "Your number is larger than the answer." | tee -a quiz1.txt else echo "Your number is smaller than the answer." | tee -a quiz1.txt fi #答えの数より入力した数が大きければ、then以下を実行してYour number is larger than the answer.と表示して、またquiz1.txtにも書き込む。 #また答えの数より入力した数が小さければ、else以下を実行してYour number is smaller than the answer.と表示して、quiz1.txtにも書き込む。 echo "What's your number?" | tee -a quiz1.txt read a #もう一度What's you number?と表示して、quiz1.txtに書き込み、新たに入力された数をaとして読み込む。 echo "$a" >> quiz1.txt #もう一度quiz1.txtに新しく入力された数をかきこむ。 done echo "Your number matches the answer!" | tee -a quiz1.txt #while文が終われば、つまり数当てに成功すれば、Your number matches the answer!と表示して、quiz1.txtにも書き込む。