Code Comments
Programming Forum and web based access to our favorite programming groups.Another question :-) I have a list of email addresses, and want to do something with them using a while loop, see echo ' aaa@example.com bbb@example.com ccc@ex.com ddd@yahoo.com ' | while read -r email; do echo "start send email to $email" mail ..... # more report to $email done By writting it this way, I got two empty email inputs in the 'while' loop. I know I can do things like: echo 'aaa@example.com bbb@example.com ccc@ex.com ddd@yahoo.com' | while read -r email; do .... done or ....| while read -r email; do if [ -n "$email" ]; then fi done My question is: can I set IFS or any other ways I can ignore all whitespaces including newlines. thanks, lihao
Post Follow-up to this messageOn 2008-04-02, lihao0129@gmail.com <lihao0129@gmail.com> wrote: > > > Another question :-) I have a list of email addresses, and want to do > something with them using a while loop, see > > echo ' > aaa@example.com > bbb@example.com > ccc@ex.com > ddd@yahoo.com > ' | while read -r email; do > echo "start send email to $email" > mail ..... > # more report to $email > done > Another way you can write this loop is while read -r email; do ... done <<EOF aaa@example.com bbb@example.com ... EOF
Post Follow-up to this messageOn Apr 2, 2:11 pm, Bill Marcum <marcumb...@bellsouth.net> wrote: > On 2008-04-02, lihao0...@gmail.com <lihao0...@gmail.com> wrote: > > > > > > Another way you can write this loop is > while read -r email; do > ... > done <<EOF > a...@example.com > b...@example.com > ... > EOF nice, I finally got this: while read -r email; do if [ -z "$email" ]; then continue; fi echo "start send email to $email" mail ..... # more report to $email done <<END_LIST aaa@example.com bbb@example.com ccc@ex.com ddd@yahoo.com END_LIST Regards, lihao
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.