I wrote a little script to send multiple mails from a list with differents subjects.


 while read -a line

 mutt -s `echo $subject` `echo $mailadd` < /home/emanuele/testomail.txt

 done < prova.txt

The scripts works fine and sends the mails, but mutt tell me that he needs a -s option.

mutt: option requires an argument -- 's'
Mutt 1.5.21 (2010-09-15)

I don't understand why the script works fine but mutt exit with an error. How can I fix it?

  • Why are you writing `echo $variable`? Why not just "$variable"? Most likely your variables are empty, and mutt just sees: mutt -s < /home/emanuele/testomail.txt – jsbillings Jul 11 '13 at 15:58
  • it is the same thing. any way i said that the script works fine. all the mails are sent and arrives to the mail server. – emanuele Jul 11 '13 at 16:23

First, `echo $subject` is a convoluted way of writing $subject (except that it mangles the value a bit more if it contains whitespace or \[*?, because $subject outside quotes is treated as a whitespace-separated list of wildcard patterns, and then the result of the whole command substitution is again treated as a whitespace-separated list of wildcard patterns).

The only way for your command to result in this error is if `echo $subject` `echo $mailadd` is empty. This happens only when both `echo $subject` and `echo $mailadd` consist only of whitespace, which in turns happens only if both variables subject and mailadd are empty (plus a few oddball cases, such as subject being the character ? and the current directory containing a file whose name is a single space). So most likely you have some blank lines in your input file.

You should always put double quotes around variable substitutions and command substitutions ("$somevar", "$(somecommand)") unless you really mean the values of the variables to be interpreted as whitespace-separated lists of file wildcard patterns.

mutt -s "$subject" "$mailaddr" <~/testeomail.txt

If there's a blank line in the input file, skip it.

while read -a line; do
  if [ -z "$subject" ]; then continue; fi
  mutt -s "$subject" "$mailadd" < /home/emanuele/testomail.txt
done < prova.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.