为什么我要继续"意想不到的EOF"在这个bash脚本中?

时间:2016-11-24 22:32:05

标签: bash

我已经写了一个bash脚本,并不断得到一个"意外的EOF"错误。我找不到它的问题。任何人都可以指出我正确的方向。任何有关如何使其更好的提示也将不胜感激。

Picture of the Error I get

这是实际的脚本

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

1 个答案:

答案 0 :(得分:3)

您的错误就在这一行:

elif [ "$ans" = "$(head -$i $1 | tail -1 | awk -F _ '{ print $2 }'" ] ; then

$()缺少结束)

elif [ "$ans" = "$(head -$i $1 | tail -1 | awk -F _ '{ print $2 }')" ] ; then

建议:1。我认为它是一个bash脚本。第一行应该是

#! /bin/bash

2。使用带语法高亮的编辑器。我正在使用凯特,还有许多其他人也可以使用。使用kate,我直截了当地发现了你的语法错误。