bash 在 mac 上运行时寻找匹配的“”错误时出现意外的 EOF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44857906/
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-09-18 16:16:04  来源:igfitidea点击:

got unexpected EOF while looking for matching `"' error when running on mac

bash

提问by ustcyue

run_cmd="spark-submit \
$SPARK_OPTIONS \
--conf spark.hadoop.fs.default.name=file:/// \
--conf spark.hadoop.fs.defaultFS=file:/// \
--py-files \
${TARGET}/test.zip \
$TEST_PY \
$RAW_DATA_FILE \
$OUTPUT \
--route $AGG_OUTPUT1 \
--origin $AGG_OUTPUT2 \
--first $AGG_OUTPUT3" #line 71

echo $run_cmd
echo $run_cmd | bash 
#line 75                       

The code is like above, it can run successfully on Ubuntu. However, when I run it on my macbook, the spark-submitfinishes normally and output is also generated correctly, but then it outputs an error, it really sounds unreasonable. Also, if spark-submitexited abnormally, it won't trigger this error.

代码如上,可以在Ubuntu上成功运行。但是,当我在我的macbook上运行它时,spark-submit完成正常并且输出也正确生成,但是它输出错误,这听起来很不合理。另外,如果spark-submit异常退出,也不会触发这个错误。

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

回答by janos

You haven't posted all the relevant code, only some lines near 60~75. The error you are getting happens when you have an unclosed "somewhere before the posted code. For example:

你还没有贴出所有相关的代码,只有60~75附近的一些行。当您"在发布代码之前的某处未关闭时,就会发生您遇到的错误。例如:

a="

b="something"

If you run this script with bash, it will report:

如果您使用 运行此脚本bash,它将报告:

script.sh: line 3: unexpected EOF while looking for matching `"'
script.sh: line 4: syntax error: unexpected end of file

As in your case, the error is reported not on the line that didn't close the ", but somewhere else. What happens, Bash interprets the value of aas \n\nb=, and then there is an opening "after somethingthat's never closed.

与您的情况一样,错误不是在没有关闭 的行上报告的",而是在其他地方报告的。会发生什么事,Bash解释的价值a\n\nb=,再有是一个开放"之后something是从未关闭。

The same thing is happening in your code. Look for a "that isn't properly closed earlier in your script.

同样的事情发生在您的代码中。"在脚本中查找之前未正确关闭的 。