From: lihao on
Hi, folks: I want to send an email to a bunch of people with the mail
CC list, the list is not small and is expecting frequently change in
the future. so I hope to maintain this list in a text file with one
email per line.i.e.:

bash~ cat emails.lst
user1(a)example.com
user2(a)example.com
user3(a)example.com
.......
user100(a)email.com
---

Is there a better `bash` way to put this list in the CC line,
currently I am using something like:

LIST="$(tr '\n' ',' <emails.lst)"
mail -s "A test mail" -c "${LIST%,}" admin(a)example.com <<END_EMAIL

blabla...

END_EMAIL

BTW. is there any limit on the length of the CC list?
many thanks,
lihao
From: Thomas 'PointedEars' Lahn on
lihao wrote:

> Hi, folks: I want to send an email to a bunch of people with the mail
> CC list, the list is not small and is expecting frequently change in
> the future. so I hope to maintain this list in a text file with one
> email per line.i.e.:
>
> bash~ cat emails.lst
> user1(a)example.com
> user2(a)example.com
> user3(a)example.com
> ......
> user100(a)email.com
> ---
>
> Is there a better `bash` way to put this list in the CC line,
> currently I am using something like:
>
> LIST="$(tr '\n' ',' <emails.lst)"
> mail -s "A test mail" -c "${LIST%,}" admin(a)example.com <<END_EMAIL
>
> blabla...
>
> END_EMAIL

LIST=$(cat emails.lst)
LIST=${LIST//'
',}
mail -s 'A test mail' -c "${LIST%,}" admin(a)example.com <<END_EMAIL
blabla...
END_EMAIL

${x//foo/bar} replaces all occurences of `foo' in $x with `bar'.
See `man ${_SHELL:-sh} | less -p '^[[:space:]]*Parameter[[:space:]]'.

It is a bit more the `bash' way, but whether that is better depends.
Both `tr' and `cat' are part of the GNU coreutils, and ${...//.../}
probably requires a newer GNU bash.

> BTW. is there any limit on the length of the CC list?

Yes, the command line length. I would be using Bcc (-b) or use a real
mailing list or another sendmail wrapper like PHP's mail() instead.


PointedEars