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

发布于 2024-12-19 23:17:05 字数 300 浏览 2 评论 0原文

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

$message=$line1$line2$line3$line

echo $message | mail -s "$subject" [email protected]

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

I need to send email by bash script:

$message=$line1$line2$line3$line

echo $message | mail -s "$subject" [email protected]

How insert end of lines so body of email I can see divided by rows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

°如果伤别离去 2024-12-26 23:17:05

使用heredoc格式怎么样?

mail -s "$subject" [email protected] << MSG_BODY_HERE
$line1
$line2
$line3
$line4
MSG_BODY_HERE

How about using heredoc format;

mail -s "$subject" [email protected] << MSG_BODY_HERE
$line1
$line2
$line3
$line4
MSG_BODY_HERE
装迷糊 2024-12-26 23:17:05

试试这个:

message="$(printf '%s\n' "$line1" "$line2" "$line3" "$line")

echo "$message" | ...

Try this:

message="$(printf '%s\n' "$line1" "$line2" "$line3" "$line")

echo "$message" | ...
dawn曙光 2024-12-26 23:17:05

使用 echo -e $message | 来自 echo 手册的邮件

-e 启用反斜杠转义的解释

use echo -e $message | mail

From echo manual:

-e enable interpretation of backslash escapes

客…行舟 2024-12-26 23:17:05
message="${line1}\n${line2}\n${line3}${line}\n"
message="${line1}\n${line2}\n${line3}${line}\n"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文