Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop problems

Status
Not open for further replies.

ryanc2

MIS
Apr 18, 2003
73
US
I need to process a loop continuously - once for each value in a file and then start over with the first value again.

list.txt has two values in it:

file1
file2

I need have a continous loop processing once for file1, then file2, then file1, then file2, etc. Currently, it processes file 1, then file2, then exits.

If I start with:

while :
do
for f in `cat list.txt`
do
commands...
done
done

It runs through successfully for file1, then file2, then reads file1 and file2 together on the third loop.

Any help would be appreciated.

 
Try something like this:
Code:
mylist=`cat list.txt`
while :
do
     for f in $mylist
     do
          commands...
     done
done


Hope This Help
PH.
 
Thanks for the quick response. However, I'm still having the same problem. Works for the first pass, but the third pass reads line 1 and line 2 together from the list.

 
I guess you change the value of the IFS variable within the inner loop, don't you ?

Hope This Help
PH.
 
Not an elegant solution I know, but what about having the script rerun itself in the last line ?
 
Give us more infos about commands you execute in the internal loop.

Jean Pierre.
 
This gets around any IFS problems, (assuming the script has no parameters)...
[tt]
set `cat list.txt`
while :
do
for f
do
commands...
done
done[/tt]
 
Thanks Ygor! That seemed to do it.

Thanks to everyone for their help...this forum is great!
 
here's another of many ways:

while :
do
while read f
# commands...
done < list.txt
done

Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top