Reputation: 24774
I try send a mail with mail
command, with the output of other command in the subject
subj="hello from $(hostname -s) $(date)"
echo "data" | mail -s $subj mail@mail
but I only get the first part of subject (hello from
).
why?
Upvotes: 2
Views: 6622
Reputation: 290
/youScriptOrOutput.sh | mail -s "Subject from host $(hostname -s) $(date)" [email protected]
Upvotes: 0
Reputation: 274758
You need to quote your subject, like this:
echo "data" | mail -s "$subj" mail@mail
If you don't quote it, the mail
program will not know where your subject ends and will take the first "word" (hello
) as the subject and everything else as an address.
In general, it is good practice to always quote your variables.
Upvotes: 7