On Thu, Sep 09, 2010 at 10:15:01PM -0600, Tim Chase wrote:
> The following reply was made to PR system/6462; it has been noted by GNATS.
> From: Tim Chase <[email protected]>
> To: [email protected]
> Cc: [email protected]
> Subject: Re: system/6462: find(1) -print wtf [non-bug]
> Date: Thu, 09 Sep 2010 21:37:51 -0500
>
> On 09/09/10 20:37, [email protected] wrote:
> > [...@fuyu xxx]$ touch foo.orig
> > [...@fuyu xxx]$ touch foo.rej
> > [...@fuyu xxx]$ find . -type f -name \*.orig -or -name \*.rej
> > ./foo.orig
> > ./foo.rej
> > [...@fuyu xxx]$ find . -type f -name \*.orig -or -name \*.rej -print
> > ./foo.rej
>
> Not a bug, but rather order of operations & short-circuit logic
> evaluation.
Perhaps we could help other people avoid this misunderstanding by
changing the last EXAMPLE in find(1) to
$ find . \( -name \*.jpg -or -name \*.gif \) -print0 | xargs -0r rm
This would demonstrate proper form, too: use print0 when dealing with
untrusted filenames (which could be
'myfile.jpg\npasswd\nmyotherfile.jpg', with \n standing for newlines -
executing the given command in /etc would have nasty consequences.)
Joachim