[lug] Joining commands?

Tkil tkil at scrye.com
Wed Apr 7 19:34:16 MDT 2004


>>>>> "Zan" == Zan Lynx <zlynx at acm.org> writes:

Zan> There is also xargs, which has several nice features and is used
Zan> like this:

Zan> find / -name '*.au' | xargs audioplay

Or, for the more paranoid in the crowd, with reasonably modern 'find'
and 'xargs' executables:

   find / -name '*.au' -print0 | xargs -0 audioplay

One other useful trick with xargs is to handle the case of no files
being found; this usually results in the named command being launched
with no args, which can often defaults to listening on stdin (and thus
hanging your shell script).  A workaround is to give /dev/null as an
input:

   find / -name '*.au' -print0 | xargs -0 audioplay /dev/null

That guarantees that 'audioplay' will always see at least one file.

t.




More information about the LUG mailing list