2017-01-31 66 views
1

我試圖通過電子郵件發送多個文件,但在電子郵件中也包含正文消息,我嘗試了幾種方法沒有運氣,以下代碼是發送多個文件:通過電子郵件發送多個文件,並向電子郵件添加正文消息(Unix Korn Shell)

(uuencode file1.txt file1.txt ; uuencode file2.txt file2.txt) | mailx -s "test" [email protected]

我試過這個選項沒有運氣:

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

任何想法,怎麼可能是代碼?

回答

1

試試這個:

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

在命令中的問題是,你是管道echo輸出到子shell,它是越來越忽略,因爲uuencode不是從標準輸入讀取。

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

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

如果您在腳本中這樣做的,你希望它看起來更具可讀性,則:

{ 
    echo "This is the body message" 
    uuencode file1.txt file1.txt 
    uuencode file2.txt file2.txt 
} | mailx -s "test" [email protected] 
+1

這是真棒!作爲一種魅力工作! –

相關問題