bugfindutils - Bugs: bug #26883, "or" condition and -exec...

 
 

bug #26883: "or" condition and -exec directive

Submitter:  Dawid Marcin Grzesiak <dawidmarcin>
Submitted:  Thu 25 Jun 2009 10:27:25 AM UTC
   
 
Category:  find Severity:  3 - Normal
Item Group:  Wrong result Status:  Invalid
Privacy:  Public Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  4.4.0 Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 25 Jun 2009 06:59:05 PM UTC, comment #4: 

Using tr and xargs -0 is not secure; in other words, it is the same as if you had done:


find -iname '*.scala' -o -iname '*.java' | xargs echo


The whole point of 'xargs -0' is that it is only useful if you already had secure file names passed to xargs in the first place.

You probably want:


find \( -iname '*.scala' -o -iname '*.java' \) -print0 | xargs -0 echo


Eric Blake <ericb>
Group administrator
Thu 25 Jun 2009 02:01:31 PM UTC, comment #3: 

Oh yes, it works. Simple thing but quite confusing. Sorry about that.

Before you replay I temporary solved it using this approach:


find -iname '*.scala' -o -iname '*.java' | tr '\n' '\0' | xargs -0 echo


I tried -print0 option, but as you mention, it takes precedence before -or operator.

Thanks,
Dawid

Dawid Marcin Grzesiak <dawidmarcin>
Thu 25 Jun 2009 12:06:20 PM UTC, comment #2: 

In reading the email sent from the last comment, it looks like savannah interpreted what it thought was markup in my sample command line (plus I had a typo).  Here's another try, this time with what I hope is the appropriate markup to capture it as literal text.  You meant to type:


find \( -name '*.txt' -o -name '*.dat' \) -exec echo {} \;


Eric Blake <ericb>
Group administrator
Thu 25 Jun 2009 11:58:29 AM UTC, comment #1: 

Not a bug.

find -name '*.txt' -o -name '*.dat'

is equivalent to:

find \( -name '*.txt' -o -name '*.dat' \) -print

Your second example:

find -name '*.txt' -o -name '*.dat' -exec echo {} \;

is equivalent to:

find -name '*.txt' -o \( -name '*.dat' -a -exec echo {} \; \)

In short, -a binds tighter than -o, and putting two operators side-by-side is equivalent to using -a between them.  You meant to type:

find \( -name '*.txt' -o -name '*.dat' -\) -exec echo {} \;

Eric Blake <ericb>
Group administrator
Thu 25 Jun 2009 10:27:25 AM UTC, original submission:  

See this bug:


$ find -name '*.txt' -o -name '*.dat'
./a.txt
./b.dat
./b.txt
./a.dat



$ find -name '*.txt' -o -name '*.dat' -exec echo {} \;
./b.dat
./a.dat


For the second invocation, the output should be exactly the same as for the first one.

Kind regards,
Dawid,
http://www.dmg.pl/

Dawid Marcin Grzesiak <dawidmarcin>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ericb (Posted a comment)
  • -email is unavailable- added by dawidmarcin (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-06-25 ericb StatusNone Invalid
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code