shell腳本+mutt:mutt終止while循環

shell腳本+mutt:mutt終止while循環

我有問題雜種狗在我的 shell 腳本中過早退出 while 循環。這閱讀 MAILTO 時我的函數的循環傳送文件只會處理(發送)第一個文件,然後回傳。但是,如果我從函數中註解掉“/usr/bin/mutt”,則目錄中的所有檔案都會正確處理。

任何人都知道為什麼會發生這種行為以及如何解決它?

#!/bin/sh
# sendReports.sh

# sendFiles function    
sendFiles ()
{
  cd $1
  ls -1 *@* | while read MAILTO
  do
    echo "Emailing file: $MAILTO"
    /usr/bin/mutt -s "Your file" -a $MAILTO -- $MAILTO
    rm -f $MAILTO
  done
}

# .... later in the life of this script ....
sendFiles /tmp/reports

# (end of file)

答案1

Mutt 在發送電子郵件後進入互動模式,這會打破您< /dev/null在 mutt 請求末尾添加的循環

例子:

/usr/bin/mutt -s "Your file" -a $MAILTO -- $MAILTO < /dev/null

相關內容