我寫了一個bash腳本,並不斷收到「意外的EOF」錯誤。我找不到它的問題。任何人都可以請我指出正確的方向。任何提示如何我可以做得更好,也將不勝感激。爲什麼我在這個bash腳本中一直收到「Unexpected EOF」?
這裏是實際的腳本
figlet -ctf slant "3-Way-Riddles"
toilet -f term -F border --gay "Remember, all the questions have a \"ONE WORD\" answer!!!"
read -p "Please press the [Enter] key to continue: "
read -p "Player One, please enter your name: " playerOne
read -p "Player Two, please enter your name: " playerTwo
one="0"
two="0"
function playerName() {
read -p "Who is answering these questions? " name
if [[ "${name,,}" != "${playerOne,,}" && "${name,,}" != "${playerTwo,,}" ]] ; then
echo -e "Wrong name input, please enter your name again.\n"
playerName
fi
}
function points() {
if [ "$name" = "$playerOne" ] ; then
one=$((one+1))
return $one
else
two=$((two+1))
return $two
fi
}
function echoPoints() {
echo -e "$playerOne has $one points\n$playerTwo has $two points"
}
function progress() {
if [ "$one" -gt "$two" ] ; then
echo Winner is \$playerOne with \$one points.
exit 0
elif [ "$one" -lt "$two" ] ; then
echo Winner is \$playerTwo with \$two points.
exit 0
else
questions ~/TechnicalWritting/Random.txt
fi
}
function questions() {
line="$(wc -l $1 | awk '{print $1}')"
for ((x = 1 ; x <= 2 ; x++)) ; do
for ((i = 1 ; i <= "$line" ; i++)) ; do
read -p "$(head -$i $1 | tail -1 | awk -F _ '{print $1}')" ans
if [ "$ans" = "" ] ; then
echo 2&1 Sorry, wrong answer.
elif [ "$ans" = "$(head -$i $1 | tail -1 | awk -F _ '{ print $2 }'" ] ; then
echo Good job random fella.
points
else
echo 2&1 Sorry, wrong answer.
fi
done
done
}
questions ~/TechnicalWritting/Math.txt
questions ~/TechnicalWritting/Logic.txt
questions ~/TechnicalWritting/Funny.txt
progress
我想你可以開始調試這個孤立的問題。例如,通過評論除第一行之外的所有行。檢查是否有效。然後取消第二個註釋。等等。 –
'echo 2&1'不正確;它在後臺運行'echo 2',然後嘗試執行一個名爲'1'的命令。如果你正試圖向stderr發送消息,你需要'echo message1>&2'。此外,'回聲贏家是\ $ playerOne \ 1分.'從字面上打印'贏家是\ $ playerOne與\ $ 1分。它不擴展變量名稱。 –
@KeithThompson我遵循了你的建議,仍然得到完全相同的錯誤信息。感謝您爲我解決這些問題。 –