#!/bin/bash echo "What's your number?" echo "What's your number?" > quiz1.txt #予想した数字をいれるように指示。そしてquiz1.txtに疑問文を書き込む read a #上の数値を読み込む echo $a >> quiz1.txt #予想した数字をquiz1.txtに書き込む while test $1 != $a #もし最初に指定した答えと予想した数字が等しくなければ次に以下のことを繰り返す do if [ $a -gt $1 ] #もし$a>$1ならば then echo Your number is larger than the answer. echo Your number is larger than the answer. >> quiz1.txt #左のようにquiz1.txtに書き込む else echo Your number is smaller than the answer. echo Your number is smaller than the answer. >> quiz1.txt #$a<$1なら左のようにquiz1.txtに書き込む fi echo "What's your number?" echo "What's your number?" >> quiz1.txt #また数字を予想するように指示する。 read a #数値を読み込む echo $a >> quiz1.txt #予想した数字をquiz1.txtに書き込む done echo Your number matches the answer! echo Your number matches the answer! >> quiz1.txt #$1=$aならば、左のようにquiz1.txtに書き込む