cancel
Showing results for 
Search instead for 
Did you mean: 

script

SOLVED
Go to solution
Piotr Kirklewski
Super Advisor

script

Hi there
I have a file with a bunch of e-mail addresses in it.
How do I display (or perform any other task) each and every e-mail address from this file ?

EMAIL=`cat eaccounts`

for ARG in "$EMAIL"
do
echo $ARG
done

Unfortunately the above method will print a list of e-mail addresses instead of one per time. Which proves that there is only one ARG which looks something lie this: user1@dom.com user2@dom.com user3@dom.com etc.
How do I make the script know there are multiple addresses in this file please ?

Regards
Peter
Jesus is the King
3 REPLIES
Steven Schweda
Honored Contributor
Solution

Re: script

> I have a file [...]

On what?

uname -a

It's nice that at least one of us can see
what's in that file. It might be nicer if
_more_ than one of us could see what's in
that file.

> for ARG in "$EMAIL"

Did you try anything like, say:
for ARG in $EMAIL
?

If the items in the file are arranged one per
line, like, say:

$ cat em.dat
line 1
line 2
line 3

then a while-read loop could be used:

$ cat em.sh
#!/bin/sh

(
while read line ; do
echo "$line"
done
) < em.dat

$ ./em.sh
line 1
line 2
line 3
Piotr Kirklewski
Super Advisor

Re: script

#!/bin/sh

(
while read line ; do
echo "$line"
done
) < em.dat

Worked for me.
Thanks
Jesus is the King
Dennis Handly
Acclaimed Contributor

Re: script

>while read line; do ... Worked for me.

And so would Steven's first suggestion of removing those quotes:
for ARG in $(< eaccounts); do
echo $ARG
done