Is there a possibility to add multiple e-mails to a single variable so that when the shell script is run, it sends a mail to all the specified emails?

  • u will have to use shell script to get different email ids & run mail command with each email ids. Probably you can use a array variable to store email ids or get it from a file. Click here link
    – Tingrammer
    Commented Jul 4, 2014 at 7:12
  • 1
    Please edit your question and show us the command you use to send email to a single address.
    – terdon
    Commented Jul 4, 2014 at 8:56

2 Answers 2


Assuming you use sendmail or mail in your script (which both expect a comma separated string as list of recipients), you can concatenate the IDs (or directly write them as such a list):

$: recipients="[email protected], [email protected], [email protected]"

or concatenating:

$: base_recipients="[email protected], [email protected]"
$: full_recipients="$base_recipients, [email protected]"

$: echo $full_recipients
[email protected], [email protected], [email protected]  

The following would be an example sending a mail with sendmail to 3 different mail IDs:


recipients="[email protected], [email protected], [email protected]"
subject="Mail to you all"
from="[email protected]"

message_txt="Hi all!\n This is a message to all 3 of you!.\n cheers, Me."

/usr/sbin/sendmail "$recipients" << EOF

Here's my code using mail array:

MAILADDR=([email protected] [email protected] [email protected])
for i in "${MAILADDR[@]}"
         echo "Mail test..." | mail -s "Mail test subject..." $i

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .