我在尝试执行一个命令时遇到了 EOF 错误。发生了什么?

我在尝试执行一个命令时遇到了 EOF 错误。发生了什么?

所以,我是 Ubuntu 20.04 的新用户,我一直在尝试弄清楚如何制作自己的命令。我一直在尝试用一系列 if-then 语句制作一个命令来弄清楚它们是如何工作的,但我一直收到相同的错误。这是代码:

    echo "Would you like to see the secret? (Y/N)"
read AFFIRM
if [$AFFIRM == Y]; then
    echo "Alright, but first I need to ask a few questions. Ready? (Y/N)"
    read AFFIRM2
    if [$AFFIRM2 == Y]; then
        echo "Great. First, what is the name of this computer?"
        read COMNAME
        if [$COMNAME == thesynthetichuman -o $COMNAME == Computer X]; then
            echo "Correct! Next question: What was the name of the first user on this computer?
            read USERNAME
            if [$USERNAME == synthetichuman]; then
                echo "Correct again! Last question: What is your favorite color?"
                read FAVCOLOR
                echo $FAVCOLOR >> " eh? Nice. Here is the secret!
//ascii art
?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII????????????IIIIIIIIIIIIIIIIIIIIIIIIIIIIIII?+++
?IIIIIIIIIIIIIIIIIIIIIIIIIII????++++++++++++++????IIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIII?++++++??????????????++++++?IIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+++???????????????????????++IIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????????????????????????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????????????????????????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????++IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????++IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????++IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????++IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????++IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????????????????????????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIII+++??????????????????????+++IIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIII?+++++++????????????+++++++IIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIIIIII???++++++++++++++???IIIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++++++++++?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+????????++?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++++++++++?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++++++++++?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIII?I???III?????+++??????+++?????????????IIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIII?++++++++++++++++++++++++++++++++++++++++++++?IIIIIIIIIIIIIII+++
?IIIIIIIIIIIII??++??++????????????????????????++????????++??++??IIIIIIIIIIIII+++
?IIIIIIIIIIII+??????+???????????????????????+?++?????????+????+++IIIIIIIIIIII+++
?IIIIIIIIIII?+++????+???????++++??++++????????+++????????+????+++?IIIIIIIIIII+++
?IIIIIIIIIII+++++???+???????++++++++++????????+++????????+??++??+?IIIIIIIIIII+++
?IIIIIIIIIII+???+++++?????+++???++???+++????????+????????++++???+?IIIIIIIIIII+++
?IIIIIIIIIII+?????+++???????+???++???+??????????+????????+++????+?IIIIIIIIIII+++
?IIIIIIIIIII+++++???+????????+++??+++???????????+???????++???++++?IIIIIIIIIII+++
?IIIIIIIIIII+????+++++????????++++++????????+???+?++????+++++???++IIIIIIIIIII+++
?IIIIIIIIIII+???????++??????????++??????????????+???????++??????++IIIIIIIIIII+++
?IIIIIIIIIII+???????++++??????????????????????+++?????+++???????+?IIIIIIIIIII+++
?IIIIIIIIIII++++?????+??+?????????????????????+++???+++++?????+++?IIIIIIIIIII+++
?IIIIIIIIIII+?+++????+II?++++++???????????????+++++++?II+???++??++IIIIIIIIIII+++
?IIIIIIIIIII+?????++++IIII++++++++++++++++++++++++IIIIII++??????++IIIIIIIIIII+++
?IIIIIIIIIII++??????++IIII+++?????????????++++++++IIIIII+?????+++?IIIIIIIIIII+++
?IIIIIIIIIII+++++????+IIII+++++++????????????????+IIIIII+???+++++?IIIIIIIIIII+++
?IIIIIIIIIII+???++???+IIII+++?++++++++++++++++++++IIIIII+?+++???++IIIIIIIIIII+++
?IIIIIIIIIII??????++++IIII++??????????++++++++++++IIII??++++?????IIIIIIIIIIII+++
?IIIIIIIIIIIII??I???++IIII++++???????????????????+IIII??++???IIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIII?IIII++????????++++++++++++++IIIIII?IIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIII+++????????????????????+IIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIII++++++++??????????????++IIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIII++?????+++++++++++++++++IIIIIIIIIIIIIIIIIIIIIIIIIII+++
+?????????????????????????+++????????+++++++++??++???????????????????????????+++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                                                 GlassGiant.com"

            else
                echo "Wrong!"
            fi
        else
            echo "Wrong!"
        fi
    

    elif [$AFFIRM == N]; then
        echo "Okay then. Bye!"

    else
        echo "Look, I had very specific instructions. Why did you ignore them? Y or N. That is it. Come on."
    fi

elif [$AFFIRM == N]; then
    echo "Okay then. Bye!"

else
    echo "Look, I had very specific instructions. Why did you ignore them? Y or N. That is it. Come on." // I seem to be getting "unexpected EOF while looking for matching `"'" errors on lines like this.

fi
echo "Bye!"
//syntax error: unexpected end of file???

我很困惑。EOF 错误出现在看似随机的行上,而且语法错误无论如何都会出现。我不知道如何修复这些错误,到目前为止我所有的谷歌搜索都是徒劳的。有人能帮忙吗?

答案1

保持社交距离,我很无聊……
有语法错误、缺少引号、逻辑错误。
你必须逐行查看才能看到我做了什么更改……在 if 语句中引用字符串时,我总是使用引号……在某些情况下,你必须这样做。在嵌套 if 时使用注释……正如 turbulence 提到的……在进行故障排除时,我逐部分测试,直到它起作用(我甚至了解了 if 语句拆分参数)

#!/bin/bash
echo "Would you like to see the secret? (Y/N)"
read AFFIRM

if [ $AFFIRM == "Y" ]; then
    echo "Alright, but first I need to ask a few questions. Ready? (Y/N)"
    read AFFIRM2

    if [ $AFFIRM2 == "Y" ]; then
        echo "Great. First, what is the name of this computer?"
        read COMNAME
        if [ "$COMNAME" == "thesynthetichuman" -o "$COMNAME" == "Computer X" ]; then
            echo "Correct! Next question: What was the name of the first user on this computer?"
            read USERNAME
            if [ $USERNAME == "synthetichuman" ]; then
                echo "Correct again! Last question: What is your favorite color?"
                read FAVCOLOR            
                echo  $FAVCOLOR "eh? Nice. Here is the secret!


?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII????????????IIIIIIIIIIIIIIIIIIIIIIIIIIIIIII?+++
?IIIIIIIIIIIIIIIIIIIIIIIIIII????++++++++++++++????IIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIII?++++++??????????????++++++?IIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+++???????????????????????++IIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????????????????????????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????????????????????????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????++IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????++IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????++IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????++IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????++IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII++??????++??????????++??????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIII?+??????????????????????????+?IIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIII+++??????????????????????+++IIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIII?+++++++????????????+++++++IIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIIIIII???++++++++++++++???IIIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++++++++++?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+????????++?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++++++++++?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++++++++++?IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIII?I???III?????+++??????+++?????????????IIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIII?++++++++++++++++++++++++++++++++++++++++++++?IIIIIIIIIIIIIII+++
?IIIIIIIIIIIII??++??++????????????????????????++????????++??++??IIIIIIIIIIIII+++
?IIIIIIIIIIII+??????+???????????????????????+?++?????????+????+++IIIIIIIIIIII+++
?IIIIIIIIIII?+++????+???????++++??++++????????+++????????+????+++?IIIIIIIIIII+++
?IIIIIIIIIII+++++???+???????++++++++++????????+++????????+??++??+?IIIIIIIIIII+++
?IIIIIIIIIII+???+++++?????+++???++???+++????????+????????++++???+?IIIIIIIIIII+++
?IIIIIIIIIII+?????+++???????+???++???+??????????+????????+++????+?IIIIIIIIIII+++
?IIIIIIIIIII+++++???+????????+++??+++???????????+???????++???++++?IIIIIIIIIII+++
?IIIIIIIIIII+????+++++????????++++++????????+???+?++????+++++???++IIIIIIIIIII+++
?IIIIIIIIIII+???????++??????????++??????????????+???????++??????++IIIIIIIIIII+++
?IIIIIIIIIII+???????++++??????????????????????+++?????+++???????+?IIIIIIIIIII+++
?IIIIIIIIIII++++?????+??+?????????????????????+++???+++++?????+++?IIIIIIIIIII+++
?IIIIIIIIIII+?+++????+II?++++++???????????????+++++++?II+???++??++IIIIIIIIIII+++
?IIIIIIIIIII+?????++++IIII++++++++++++++++++++++++IIIIII++??????++IIIIIIIIIII+++
?IIIIIIIIIII++??????++IIII+++?????????????++++++++IIIIII+?????+++?IIIIIIIIIII+++
?IIIIIIIIIII+++++????+IIII+++++++????????????????+IIIIII+???+++++?IIIIIIIIIII+++
?IIIIIIIIIII+???++???+IIII+++?++++++++++++++++++++IIIIII+?+++???++IIIIIIIIIII+++
?IIIIIIIIIII??????++++IIII++??????????++++++++++++IIII??++++?????IIIIIIIIIIII+++
?IIIIIIIIIIIII??I???++IIII++++???????????????????+IIII??++???IIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIII?IIII++????????++++++++++++++IIIIII?IIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIII+++????????????????????+IIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIII++++++++??????????????++IIIIIIIIIIIIIIIIIIIIIIIIIII+++
?IIIIIIIIIIIIIIIIIIIIIIIII++?????+++++++++++++++++IIIIIIIIIIIIIIIIIIIIIIIIIII+++
+?????????????????????????+++????????+++++++++??++???????????????????????????+++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                                              glassassnt.com"
                                                                                             
            else
                echo "Wrong!" #username
            fi
        else
            echo "Wrong!" #comname
        fi
    elif [ $AFFIRM2 == "N" ]; then
        echo "Okay then. Bye!" #affirm2

    else
        echo "Look, I had very specific instructions. Why did you ignore them? Y or N. That is it. Come on."
    fi

elif [ $AFFIRM == "N" ]; then
    echo "Okay then. Bye!" #affirm
else
    echo "Look, I had very specific instructions. Why did you ignore them? Y or N. That is it. Come on."
fi

echo "Bye!"

相关内容