[Home]MuttGuide/ShellScripting

MuttWiki | MuttGuide | RecentChanges | Preferences | EDITwiki

Specifying multiple filenames to attach in a shell script

The following is an example of using Mutt to send a set of files specified on the command line as attachments to a predefined recipient. Note that special handling is required when dealing with filenames that contain spaces. The for loop ensures that each filename will be enclosed in double quotes. Then, mutt is invoked with the eval to remove the double quotes and deliver the filename intact.

#!/bin/bash

for i in "$@"; do
        qFile='"'$i'"'
        allFiles="$allFiles -a $qFile"
done

subj='test message'
qSubj='"'$subj'"'
recip='user@host'

eval mutt -s $qSubj $allFiles $recip < /dev/null

MuttWiki | MuttGuide | RecentChanges | Preferences | EDITwiki
Read EDITwiki in nav-bar!!! | View other revisions
Last edited November 9, 2007 2:06 pm by MichaelElkins (diff)
Search: