Subject: Re: Recursive grep (find, xargs, etc)
To: None <current-users@NetBSD.ORG>
From: der Mouse <mouse@collatz.mcrcim.mcgill.edu>
List: current-users
Date: 01/31/1996 10:00:28
>> netbsd4me:1:34 [/tmp] % ls -l test
>> total 0
>> -rw-r--r--  1 earle  wheel  0 Jan 23 14:13 This file has spaces in it
>> netbsd4me:1:35 [/tmp] % find . -type f -print | xargs egrep -l foo
>> egrep: ./test/This: No such file or directory
>> egrep: file: No such file or directory
>> egrep: has: No such file or directory
>> egrep: spaces: No such file or directory
>> egrep: in: No such file or directory
>> egrep: it: No such file or directory

>      -X      The -X option is a modification to permit find to be safely used
>              in conjunction with xargs(1).  If a file name contains any of the
>              delimiting characters used by xargs,  a diagnostic message is
>              displayed on standard error, and the file is skipped. [...]

How utterly misguided: an option that makes find unnecessarily skip
things, to kludge around severe braindamage in xargs.  If you're having
trouble with xargs, fix args, not find - this is as silly as fixing cc
to interpret "if (foo = bar)" as "if (foo == bar)" instead of
retraining your fingers to type the latter instead of the former.

A much better solution would be to fix xargs to make it (perhaps
optionally) behave usefully instead of standards-conformingly.  For
example:

% ls -l test
total 0
-rw-r--r--  1 earle  wheel  0 Jan 23 14:13 This file has spaces in it
% find . -type f -print | xargs -useful egrep -l foo
% 

I can - barely - understand wanting xargs to handle spaces, tabs, and
quotes.  I cannot understand what possessed anyone to think it would be
appropriate to have it default to behaving that way; this is worse than
having find default to -print0 - at least that one got sanity-checked
before it went anywhere; this one actually made it into a standard
somehow.  (As regular readers of my rants know, I am generally in favor
of ignoring standards whenever they get in the way of usefulness.  In
the case of xargs, standard conformance is outright crippling to
usefulness; I would much prefer to change xargs to default to using
just newlines, optionally NULs, with (for pedants and the odd occasion)
a -stupid (alright, alright, -posix) flag to get the
whitespace-and-quotes behavior.)

Fortunately, the issue is more or less moot, given the -print0 flag to
find and the -0 flag to xargs.

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu