In article <bob-A81B29.15162506022008@[EMAIL PROTECTED]
>,
Robert Peirce <bob@[EMAIL PROTECTED]
> wrote:
> In sh and ksh, I have used
>
> for i in `cat file`
> do
> do-something-with-$i
> done
>
> on other systems with no problem. In OS X, this sometimes hangs, but
> sometimes it doesn't, which is very confusing. Pr also hangs, but for
> some strange reason, head works in the same script!
>
> Does anybody have any idea what I am doing wrong? This should always
> work fine, but sometimes it doesn't.
May I suggest
while read line
do
do-something-with-$line
done <file
This will do something similar, assuming there is one item per
line.
if you have multiple fixed items per line you can do
while read item1 item2 item3
do
do-something-with-$item1
do-something-with-$item2
do-something-with-$item3
done <file
Or if you do not know how may items are on each line you can try
while read line
do
set -- $line
for item
do
do-something-with-$item
done
done <file
Bob Harris


|