我正在使用下面的bash脚本来发送电子邮件
#!/bin/bash recipients="[email protected],[email protected]" subject="Just a Test" from="[email protected]" message_txt="This is just a test.n Goodbye!" /usr/sbin/sendmail "$recipients" << EOF subject:$subject from:$from $message_txt EOF
但是,当电子邮件到达$ message_txt内容打印字面如下所示:
This is just a test.n Goodbye!
而不是像这样解释新行:
This is just a test. Goodbye!
我试过使用:
Sendmail for Windows
将电子邮件从“bugzilla-daemon”发送到“[email protected]”时发生错误:没有发件人
echo $message_txt echo -e $message_txt printf $message_txt
但结果总是一样的。 我哪里错了?
我究竟做错了什么?
在bash中你应该使用下面的语法
message_txt=$'This is just a test.n Goodbye!'
前面带有$单引号是允许在字符串中插入转义序列的新语法。
检查以下有关ANSI C类转义序列的bash引用机制的文档
您也可以直接在字符串中嵌入换行符,而不需要转义序列。
message_txt="This is just a test. Goodbye!"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。