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

时间:2017-07-10 21:55:37

标签: linux bash unix

我们正在使用Bourne-Again Shell。

这个错误是什么意思?:

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

2 个答案:

答案 0 :(得分:2)

开头的单引号字符串
$('#Subnet tr').each(function (i, row){
        var $row = $(row);
        var $hostname =  $row.find('[headers=Hostname]');
        if($hostname.text() == '-'){
           var url = "f?p="+$v('pFlowId')+":113:"+$v('pInstance')+"::::P113_SUBNET_ID:"+$row.find('[headers=ID]').text();
           $hostname.html("<a href='"+url+"'><span class='fa fa-plus-square-o'></span></a>");
           console.log($row.find('[headers=ID]').text()+ ' / '+$row.find('[headers=Address]').text());
        }

    });

缺少结束单引号。 SO的语法突出显示也是如此。

也许你想反驳报价?

ve bricked the

还是有双引号?

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

在这种情况下,您还可以使用HERE-doc:

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

答案 1 :(得分:1)

ShellCheck很有帮助:

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

确实你做到了。也在下一行。

这里是没有语法错误的脚本(但你仍然必须修复访问它们的选项):

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