来自 bash 脚本的电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2275593/
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
email from bash script
提问by Jim
#!/bin/bash
MESSAGE="Line one. /n"
MESSAGE="$MESSAGE Line two. /n"
MESSAGE="$MESSAGE Line three."
echo $MESSAGE | mail -s "test" "[email protected]"
Is that how I should get each line, on its own line?
这是我应该如何在自己的行上获取每行?
回答by Matthew Flaschen
Use a heredoc.
使用heredoc。
mail -s "test" "[email protected]" << END_MAIL
Line one.
Line two.
Line three.
END_MAIL
回答by Jim
Change:
改变:
echo $MESSAGE | mail -s "test" "[email protected]"
To:
到:
echo -e $MESSAGE | mail -s "test" "[email protected]"
回答by DigitalRoss
The heredoc advice is good, plus you might want to consider using mailx
for which there exists a Posix standard or perhaps sendmail
which will exist if the mailer is either sendmail or postfix. (I'm not sure about qmail.)
Heredoc 建议很好,另外您可能要考虑使用mailx
存在 Posix 标准的地方,或者sendmail
如果邮件程序是 sendmail 或 postfix可能会存在。(我不确定 qmail。)
Unless using sendmail, it's also a good idea to set the MAILRC
variable to /dev/null
to bypass the user's configuration script, if any.
除非使用 sendmail,否则最好将该MAILRC
变量设置/dev/null
为绕过用户的配置脚本(如果有)。