Linux 如何修复 bash 脚本中意外的文件结尾?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11003266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:48:38  来源:igfitidea点击:

How do I fix unexpected end of file in bash script?

linuxbashshell

提问by Paul

I had much luck last time I submitted a question so here goes: I am trying to debug a somewhat large BASH script when I get the following error:

上次提交问题时我很幸运,所以这里是这样的:当我收到以下错误时,我正在尝试调试一个有点大的 BASH 脚本:

./test.sh: line 418: unexpected EOF while looking for matching `"'
./test.sh: line 427: syntax error: unexpected end of file

The code below starts at line 400:

下面的代码从第 400 行开始:

    echo "###########################################################"
    echo
;;
4)
    culebra_carriers
    get_month
    get_day
    logs_cdrs
    logs_wap
    get_mdn

    echo
    echo "###########################################################"
    echo
    echo "Searching for activity of $mobileNumber on $MON $DAY......."
    echo
    zgrep $mobileNumber $HOME/culebrapeak/$LOGCDR/$CULEB/$MON/$WAPLOG
    echo
    echo "###########################################################"
    echo
;;
esac
done
}

clear
main_menu

How do I make this error go away? It looks like I have the double quotes in all the right places... but this is only my 4th or 5th bash script... so please go easy on me.

我如何使这个错误消失?看起来我在所有正确的地方都有双引号……但这只是我的第 4 个或第 5 个 bash 脚本……所以请放轻松。

采纳答案by Paul

I was, indeed, missing a double quote at the top of my script. Thanks to all for the help!

事实上,我在我的脚本顶部遗漏了一个双引号。感谢大家的帮助!

回答by Anthony Rutledge

A good way to solve problems like this is to use a text editor that highlights code between quotes. Short of that, if the "find" feature of your text editor gives a count too, you may be able to use it to quantitatively detect start/end character symmetry problems. The highlighting from the find feature will aide your eye tremedously.

解决此类问题的一个好方法是使用文本编辑器突出显示引号之间的代码。除此之外,如果您的文本编辑器的“查找”功能也提供了计数,您也许可以使用它来定量检测开始/结束字符对称问题。查找功能的突出显示将极大地帮助您的眼睛。