Reputation: 21
I've written a bash script, and keep getting an "Unexpected EOF" error. I cannot find the issue in it. Could anyone point me to the right direction please. Any tips on how I can make it better would also be appreciated.
And here is the actual script
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
Upvotes: 1
Views: 496
Reputation: 1399
Your error is in this line:
elif [ "$ans" = "$(head -$i $1 | tail -1 | awk -F _ '{ print $2 }'" ] ; then
$()
is missing the closing )
elif [ "$ans" = "$(head -$i $1 | tail -1 | awk -F _ '{ print $2 }')" ] ; then
Recommendations: 1. I think it is a bash script. The first line should be
#! /bin/bash
2. Use an editor with syntax highlighting. I'm using kate, many other are available, too. Using kate, I straightforward found your syntax error.
Upvotes: 3