쉘 스크립트 + mutt: while 루프를 종료하는 mutt

쉘 스크립트 + mutt: while 루프를 종료하는 mutt

나에게 문제가 있습니다바보쉘 스크립트에서 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

< /dev/nullMutt는 이메일을 보낸 후 대화형 모드로 전환되며 이로 인해 mutt 요청 끝에 루프 추가가 중단됩니다.

예:

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

관련 정보