bash: Question about IFS and while loop??

bash: Question about IFS and while loop??

am 02.04.2008 19:52:00 von lihao0129

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

Re: bash: Question about IFS and while loop??

am 02.04.2008 20:11:29 von Bill Marcum

On 2008-04-02, 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 < aaa@example.com
bbb@example.com
....
EOF

Re: bash: Question about IFS and while loop??

am 02.04.2008 21:10:45 von xicheng

On Apr 2, 2:11 pm, Bill Marcum wrote:
> On 2008-04-02, lihao0...@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 '
> > a...@example.com
> > b...@example.com
> > c...@ex.com
> > d...@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 < > 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 < aaa@example.com
bbb@example.com
ccc@ex.com
ddd@yahoo.com
END_LIST

Regards,
lihao