I'm getting stuck on something that surely has a simple solution. I'm using mail from GNU mailutils to periodically send a log file to relevant people.
mail -s "The Subject" someone@example.com <<< "Message body"
Now I want to incorporate that in a script that performs a bunch of tasks, but I'm getting stuck with the expansion and the quotes.
This is what I'm trying:
subject="The Subject"
sender=From:Sender\<someone@example.com\>
recipient_list=me@example.com,another@example.com,yetanother@example.com
report="mail -s "$subject" -a $sender $recipient_list"
...
$report <<< "A log message from a section of script"
...
$report <<< "A different log message"
The trouble is with $subject.
Calling mail -s "$subject" -a $sender $recipient_list <<< "My Message"
works nicely, but wrapping it into a variable as I've done above ends up sending the email with only the first word of "The Subject" getting sent, not the whole string.
I'm going to go the proper function route, but now I'm curious. I'm sure some escape/expansion trick will do it, but I have not been able to find the correct one (or reason it out).
Thanks!