#!/bin/bash echo "What's your number?" > quiz1.txt echo "What's your number?" #プレイヤーが予想する数はいくつかを尋ねます。 read a #プレイヤーが予想した数を読み込みます echo $a >> quiz1.txt #quiz1.txtに予想した数を出力させます。 rum=$(((RANDOM % 99) + 1)) #正解の数を1〜99の間でランダムに選びます while [ $a -ne $rum ] do #正解するまで以下の操作を繰り返します if [ $a -gt $rum ] #プレイヤーが予想した数が正解の数よりも大きい時 then echo "Your number is larger than the answer. Guess the answer again." >> quiz1.txt echo "Your number is larger than the answer. Guess the answer again." #予想した数は正解の数よりも大きいと表示、quiz1.txtにも出力。 else if [ $a -le 0 ] then echo "Error! Type a natural number" #自然数以外を入力するとErrorと表示。 else echo "Your number is smaller than the answer. Guess the answer again." >> quiz1.txt echo "Your number is smaller than the answer. Guess the answer again." #その他の場合。つまり予想した数が正解の数よりも小さい時は #その旨を表示し、quiz1.txtに出力 fi fi echo "What's your number?" read a echo $a >> quiz1.txt #正解するまで繰り返す。 done echo "You got a right answer!!" echo "You got a right answer!!" >> quiz1.txt #正解すると正解!と表示して終了。