#!/bin/bash txt=quiz1.txt #出力先のファイルを指定します genuine=$1 #引数$1(正解の数字)を$genuineとします echo What\'s your number? | tee $txt read number echo $number >> $txt #予想して打ち込んだ数字がquiz1.txtに出力されます while [ $number -ne $genuine ] do #打ち込んだ数字が正解の数字と一致しない間は以下が繰り返し実行されます if test $number -gt $genuine; then echo Your number is larger than the answer. | tee -a $txt #打ち込んだ数字が正解の数字より大きければその旨が画面に表示され 同時にquiz1.txtに追記されます else echo Your number is smaller than the answer. | tee -a $txt #打ち込んだ数字が正解の数字より小さければその旨が画面に表示され 同時にquiz1.txtに追記されます fi echo What\'s your number? | tee -a $txt read number echo $number >> $txt done echo Your number matches the answer!! | tee -a $txt #打ち込んだ数字が正解の数字と一致すればその旨が画面に表示され 同時にquiz1.txtに追記されます