Problems with bash variable expanding with single quotes

Filenames are notoriously unreliable in expanded strings; resist this temptation.

Instead, use an array to keep the filenames intact, regardless of any whitespace:

arr=()
for f in $somedir/*.pdf
do
arr+=( -a "$f")
done

# and for usage/display:

mutt -s mysubject "${a[@]}" some@body

See the Bash Guide on Arrays for reference.


Use eval function

command="mutt -s \"Subject\" $ATTSTR [email protected]"
response=$(eval "$command")