私の教授は私に、私は理解できないと思うスクリプトを割り当てました。ユーザー尋ねることになっているBASH:「われわれはまだありますか?」 - 一見単純な反応ベースのスクリプト
「我々はまだありますか?」:どのようにスクリプトが動作するようになっている
(はい、シンプソンズ)、ユーザーは0、NO、1のいずれかで応答する必要があります。
0の場合、スクリプトは「THREATCOUNTER」と呼ばれるインクリメント変数を使用して脅迫メッセージを出力します。再び。
ユーザーが0を続けている場合、ユーザーが0回と言うまで、脅威メッセージはより積極的になります。 10回目に、スクリプトは「DIE」を出力します。プログラムは終了する。
ユーザがいずれかの時点で1と答えた場合、スクリプトは「Yay」と出力します。プログラムは再び終了する。
CODE:
#!/bin/bash
echo "Are we there yet?"
read input
if [ $input = 1 ]
then
echo "Yay!"
else
COUNTER=1
while [ $COUNTER -lt 10 ] do
echo "Are we there yet?"
if [ $COUNTER -eq 1] do
echo "We better get there soon or you'll be sorry!"
fi
COUNTER++
if [ $COUNTER -eq 2 ] do
echo "Oh, if you were any slower you wouldn't be mentally capable of driving!"
fi
COUNTER++
if [ $COUNTER -eq 3 ] do
echo "You better start driving faster or you're gonna be begging for mommy!"
fi
COUNTER++
if [ $COUNTER -eq 4 ] do
echo "I have an idea how you can get their faster! Put your |CENSORED| foot on the |CENSORED| pedal!"
fi
COUNTER++
if [ $COUNTER -eq 5 ] do
echo "Drive faster |CENSORED| |CENSORED|! Drive faster or I'll rip your legs off, you're not using them anyways!"
fi
COUNTER++
if [ $COUNTER -eq 6 ] do
echo "For the love of |CENSORED|, can't you actually get there! We don't have all |CENSORED| day!"
fi
COUNTER++
if [ $COUNTER -eq 7 ] do
echo "Oh my |CENSORED|, why do you have to drive as though you're your |CENSORED| great grandmother?"
fi
COUNTER++
if [ $COUNTER -eq 8 ] do
echo "Who in |CENSORED| green earth would let you drive, you torturous madman? Drive! Drive!! DRIVE!!!"
fi
COUNTER++
if [ $COUNTER -eq 9 ] do
echo "Oh for |CENSORED| sake, why haven't we gotten there yet, you worthless stick rider?"
fi
COUNTER++
if [ $COUNTER -eq 10 ] do
echo "DIE."
fi
fi
エラー:
./arewethereyet.sh: line 17: syntax error near unexpected token `fi'
./arewethereyet.sh: line 17: ` fi'
何?
'if ... do'が間違っています。 'もしあれば...。それが正しい。 – bishop
プログラムを書く言語のドキュメントを読むのに役立ちます。 – chepner