如何在bash中插入回车符和换行符



我需要通过bash脚本发送电子邮件:

$message=$line1$line2$line3$line
echo $message | mail -s "$subject" myname@somewhere.com

如何插入行尾,以便我可以看到电子邮件的正文按行划分?

使用heredoc格式如何;

mail -s "$subject" myname@example.com << MSG_BODY_HERE
$line1
$line2
$line3
$line4
MSG_BODY_HERE

试试这个:

message="$(printf '%sn' "$line1" "$line2" "$line3" "$line")
echo "$message" | ...

使用echo -e $message | mail

From echo manual:

-e允许解释反斜杠转义

message="${line1}n${line2}n${line3}${line}n"

最新更新