[PLUG] find | while read
Tim
tim-pdxlug at sentinelchicken.org
Sat Apr 12 16:58:19 UTC 2008
> I found a workaround, but it's more complex than I like. I've included
> three generations of a simplified script as an example. What I'd like to
> know is, does anyone know a more sane method for looping over a list of
> files produced by a command like find, git or anything else?
I'm not intimately familiar with what you've got going, but often I rely
on the combination of find and xargs with NUL termination. The only
characters not allowed in a file name in UNIX are '\0' and '/'. If the
file names are NUL terminated, then you don't have to worry about nasty
parsing issues. Unfortunately not too many tools support parsing based
on this, but xargs does:
find . -name '*.txt' -print0 | xargs -0 aspell -c
To do multiple commands at once for a single file, you'd probably need
to muck around with the -I option in xargs.
good luck,
tim
More information about the PLUG
mailing list