here-document 给出了“意外的文件结尾"错误 [英] here-document gives 'unexpected end of file' error
问题描述
我需要我的脚本从终端发送电子邮件.根据我在这里和网上许多其他地方看到的内容,我将其格式化为:
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
...其中第 x 行是程序中最后编写的代码行,第 y 行是其中包含 /var/mail
的行.我尝试用其他东西(ENDOFMESSAGE
、FINISH
等)替换 EOF
但无济于事.我在网上找到的几乎所有东西都是这样做的,而且我对 bash 真的很陌生,所以我很难自己弄清楚.有人可以提供任何帮助吗?
...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?
推荐答案
EOF
标记必须在行首,不能与它所在的代码块一起缩进与.
The EOF
token must be at the beginning of the line, you can't indent it along with the block of code it goes with.
如果你写 <<-EOF
你可以缩进它,但它必须用 Tab 字符缩进,而不是空格.所以即使是代码块,它仍然可能不会结束.
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.
还要确保在行上的 EOF
标记之后没有空格.
Also make sure you have no whitespace after the EOF
token on the line.
这篇关于here-document 给出了“意外的文件结尾"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!