这里的文件给出了'意外的文件结束'错误 [英] here-document gives 'unexpected end of file' error

查看:142
本文介绍了这里的文件给出了'意外的文件结束'错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的脚本从终端发送电子邮件。基于我在这里和许多其他地方在线看到的,我格式化如下:

  / var / mail -s$ SUBJECT$ EMAIL<< EOF 
这是我的消息的一行!
这里是另一行!
最后一行消息在这里!
EOF

但是,当我运行这个我得到这个警告:

  myfile.sh:line x:warning:这里的文档以文件末尾分隔(想要'EOF')

myfile.sh:line x + 1:语法错误:文件的意外结束

...其中line x是程序中最后一行代码的代码行,y行是/ var / mail的行。我尝试用其他东西替换EOF(ENDOFMESSAGE,FINISH等),但没有效果。几乎我在网上找到的一切都是这样做的,而且我真的很笨,所以我很难自己弄清楚。任何人都可以提供任何帮助吗?谢谢!

解决方案

EOF 令牌必须在行,你不能缩进它与它的代码块。



如果你写<< -EOF 您可以缩进它,但必须缩进 Tab 字符,而不是空格。所以即使有代码块仍然可能不会结束。



还要确保在 > EOF 令牌在线。


I need my script to send an email from terminal. Based on what I've seen here and many other places online, I formatted it like this:

/var/mail -s "$SUBJECT" "$EMAIL" << EOF
Here's a line of my message!
And here's another line!
Last line of the message here!
EOF

However, when I run this I get this warning:

myfile.sh: line x: warning: here-document at line y delimited by end-of-file (wanted 'EOF')

myfile.sh: line x+1: syntax error: unexpected end of file

...where line x is the last written line of code in the program, and line y is the line with /var/mail in it. I've tried replacing EOF with other things (ENDOFMESSAGE, FINISH, etc.) but to no avail. Nearly everything I've found online has it done this way, and I'm really new at bash so I'm having a hard time figuring it out on my own. Could anyone offer any help? Thanks!

解决方案

The EOF token must be at the begining of the line, you can't indent it along with the block of code it goes with.

If you write <<-EOF you may indent it, but it must be indented with Tab characters, not spaces. So it still might not end up even with the block of code.

Also make sure you have no whitespace after the EOF token on the line.

这篇关于这里的文件给出了'意外的文件结束'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆