Help on bash script?

Ian Smith smithi at nimnet.asn.au
Sat Aug 13 15:13:31 GMT 2005


On Sat, 13 Aug 2005, Giorgos Keramidas wrote:

 > On 2005-08-12 13:38, Benson Wong <tummytech at gmail.com> wrote:
 > > I prefer:
 > >
 > > for COREFILE in `find / -type f -name core -print`
 > > do
 > >   ...
 > > done
 > >
 > > Wouldn't that accomplish the same thing?
 > 
 > More or less.  Less, when the filenames are too many.  See questions
 > posted on this very same list about ``too many arguments''.

True.  Of course if you've got that many core files lying around, you
probably have other things to worry about :)

 > The ``while read line; do stuff with $line; done'' loop doesn't suffer
 > from the same limitation, but is a bit more expensive in terms of the
 > number of spawned processes and (consequently) the time it takes to run.

Maybe measurable.  Took me ages to appreciate the difference between say

   cat tempfile | while read line; do stuff with $line; done
and
   while read line; do stuff with $line; done < tempfile

when 'stuff' needs to update script-scope variables, despite a slightly
icky, impure feeling about using tempfiles .. 

cheers, Ian



More information about the freebsd-questions mailing list