【问题标题】:Send multiple files by email and also add a body message to the email (Unix Korn Shell)通过电子邮件发送多个文件并在电子邮件中添加正文消息(Unix Korn Shell)
【发布时间】:2017-01-31 22:35:07
【问题描述】:

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

(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

知道代码怎么可能吗?

【问题讨论】:

    标签: shell file email unix mailx


    【解决方案1】:

    试试这个:

    (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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多