您可以相当轻松地使用文件名列表填充数组,然后将其用作-a
.
while IFS= read -r attachment; do
attachments+=( "$attachment" )
done < listoffilestoattach.txt
for f in ../*.log; do
attachments+=("$f")
done
mutt -s "subject of message" -a "${attachments[@]}" -- myself@gmail.com < mail.txt
如果您使用的是bash
4 或更高版本,您可以用while
(稍微)更友好的readarray
命令替换循环:
readarray -t attachments < listoffilestoattach.txt
如果看起来是这样,mutt
每个选项需要一个文件-a
,那么你需要一些稍微不同的东西:
while IFS= read -r attachment; do
attachments+=( -a "$attachment" )
done < listoffilestoattach.txt
for f in ../*.log; do
attachments+=( -a "$f")
done
mutt -s "subject of message" "${attachments[@]}" -- myself@gmail.com < mail.txt
使用readarray
,尝试
readarray -t attachments < listoffilestoattach.txt
attachments+=( ../*.log )
for a in "${attachements[@]}"; do
attach_args+=(-a "$a")
done
mutt -s "subject of message" "${attach_args[@]}" -- myself@gmail.com < mail.txt