Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

bash: Question about IFS and while loop??
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

Report this thread to moderator Post Follow-up to this message
Old Post
lihao0129@gmail.com
04-03-08 12:41 AM


Re: bash: Question about IFS and while loop??
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Bill Marcum
04-03-08 12:41 AM


Re: bash: Question about IFS and while loop??
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Xicheng Jia
04-03-08 12:41 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Shell Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:06 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.