简体   繁体   English

Bash语法错误语法错误:文件意外结束

[英]Bash Syntax Error syntax error: unexpected end of file

We are using the Bourne-Again Shell. 我们正在使用Bourne-Again Shell。

What does this error mean?: 这个错误是什么意思?:

syntax error: unexpected end of file

PS3="Press 1, 2, 3, 4 to do the thing they say next to them."
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "start game")
            echo ok
            ;;
        "level select")
            echo "no"
            ;;
        "how do i exit")
            echo "click the window to close"
        xkill
            ;;
        "exit")
            echo wwaaaatttt
        echo click the window to kill it.
            xkill
            echo "if your reading this, you must have opened
            echo "a game file. you've bricked the exit
            echo button. great job.
            ;;
        *) echo not a thing, sorry;;
    esac
done

The single quoted string starting with 以单引号开头的字符串

ve bricked the

is missing the closing single quote. 缺少右引号。 SO's syntax highlighting shows it, too. SO的语法突出显示了它。

Maybe you wanted to backslash the quote? 也许您想反斜杠报价?

echo "a game file. you\'ve bricked the exit

or there are double quotes missing too? 还是也缺少双引号?

echo "if you're reading this, you must have opened"
echo "a game file. you've bricked the exit"
echo "button. great job."

In such a case, you can also use a HERE-doc: 在这种情况下,您也可以使用HERE-doc:

cat << 'EOF'
if you're reading this, you must have opened
a game file. you've bricked the exit
button. great job.
EOF

ShellCheck is helpful: ShellCheck很有帮助:

Line 20:
            echo "if your reading this, you must have opened
                 ^-- SC1078: Did you forget to close this double quoted string?

And indeed you did. 确实,您做到了。 Also on the next line. 也在下一行。

Here's the script without syntax errors (but you still have to fix the options to access them): 这是没有语法错误的脚本(但是您仍然必须修复访问它们的选项):

PS3="Press 1, 2, 3, 4 to do the thing they say next to them."
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "start game")
            echo ok
            ;;
        "level select")
            echo "no"
            ;;
        "how do i exit")
            echo "click the window to close"
        xkill
            ;;
        "exit")
            echo wwaaaatttt
        echo click the window to kill it.
            xkill
            echo "if your reading this, you must have opened" # HERE
            echo "a game file. you've bricked the exit"       # HERE
            echo button. great job.
            ;;
        *) echo not a thing, sorry;;
    esac
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM