2014-07-17 27 views
1

發送郵件我試圖使用發送郵件mailx的UUENCODE和使用的shell腳本使用mailx的

attachments=uuencode file1 file1;uuencode file2 file2; 

(echo BODY ; $attachments)| mailx -s "Attachments" -m [email protected] 

對於上面的腳本唯一的郵件沒有依附以下附件發送,但是當我使用以下

(echo BODY ; uuencode file1 file1;uuencode file2 file2;)| mailx -s "Attachments" -m [email protected] 

現在郵件與附件一起發送。

我是相當新的shellcripting kindly help。

+1

那麼問題是什麼? – konsolebox

回答

1

您使用了錯誤的報價爲命令替換:

attachments=`uuencode file1 file1;uuencode file2 file2` 

或更好

attachments=$(uuencode file1 file1;uuencode file2 file2) 

Command Substitution section of the bash man page

然後用echo輸出變量的內容

(echo BODY ; echo $attachments)| mailx -s "Attachments" -m [email protected] 
+1

這給你的輸出,就像你在我的答案中評論的那樣,但是當你管它的時候不會發送附件。你需要管道命令的輸出,所以第一部分'(echo BODY; $ attachments)'需要任何'$ attachments'擴展成一個命令,否則你會遇到一些錯誤,比如'Begin:Command not found ' – chrisb2244

+0

@ chrisb2244謝謝我沒有注意到缺少'echo'。我更新了答案。 – Matteo

+1

'mailx'在運行中處理附件的編碼。那麼爲什麼不'echo「body」| mailx -s「Attachments」-a file1 -a file2 someone @ example.com'這似乎更容易。 –