开发者

email from bash script

开发者 https://www.devze.com 2022-12-20 20:21 出处:网络
#!/bin/bash MESSAGE=\"Line one. /n\" MESSAGE=\"$MESSAGE Line two. /n\" MESSAGE=\"$MESSAGE 开发者_JAVA技巧Line three.\"
#!/bin/bash
MESSAGE="Line one. /n"

MESSAGE="$MESSAGE Line two. /n"
MESSAGE="$MESSAGE 开发者_JAVA技巧Line three."

echo $MESSAGE | mail -s "test" "example@example.com"

Is that how I should get each line, on its own line?


Use a heredoc.

mail -s "test" "example@example.com" << END_MAIL
Line one.
Line two.
Line three.
END_MAIL


Change:

echo $MESSAGE | mail -s "test" "example@example.com"

To:

echo -e $MESSAGE | mail -s "test" "example@example.com"


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.)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号