通过电子邮件发送多个文件并在电子邮件中添加正文消息 (Unix Korn Shell)

Send multiple files by email and also add a body message to the email (Unix Korn Shell)

我正在尝试通过电子邮件发送多个文件,但也在电子邮件中包含正文消息,我尝试了几种方法都没有成功,以下代码用于发送多个文件:

(uuencode file1.txt file1.txt ; uuencode file2.txt file2.txt) | mailx -s "test" email@test.com

我试过这个选项,但没有成功:

echo "This is the body message" | (uuencode file1.txt file1.txt ; uuencode file2.txt file2.txt) | mailx -s "test" email@test.com

知道代码是怎么来的吗?

试试这个:

(echo "This is the body message"; uuencode file1.txt file1.txt; uuencode file2.txt file2.txt) | mailx -s "test" email@test.com

您的命令的问题是您正在将 echo 的输出通过管道输送到子 shell 中,并且由于 uuencode 未从标准输入中读取而被忽略。

你可以使用{ ... }来避免子shell:

{ echo "This is the body message"; uuencode file1.txt file1.txt; uuencode file2.txt file2.txt; } | mailx -s "test" email@test.com

如果您在脚本中执行此操作并且希望它看起来更具可读性,那么:

{
  echo "This is the body message"
  uuencode file1.txt file1.txt
  uuencode file2.txt file2.txt
} | mailx -s "test" email@test.com