tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

find -exec ... +

So, according to the man page, in find -exec ... +, the {} is supposed
to come only immediately before the +. That is, you can do

   % find foo -exec ls -l {} +

but not

   % find foo -exec mv {} subdir/ +

As recently noted in PR 44246 it's sort of desirable to be able to do
the latter. The only reason I can think of for prohibiting this is
that allowing more flexible matching might break "logic" like

   % find foo -exec expr {} \* 2 + 3 \;

(although without the \* 2 it would end up being broken anyway)... I
suppose that's a reasonable concern, but there's a wrinkle: our find
has a bug so it doesn't enforce this, so it breaks anyway:

   % find foo -exec expr {} \* 2 + 3 \;
   find: 3: unknown option

although if you try to take advantage of this it does the wrong thing:

   % find foo -exec echo a b {} c d +
   a b {} c foo foo/bar foo/baz

because it always substitutes into the argument before the +
regardless of whether that's the {}.

This bug can be fixed as such with a one-line patch, which makes it
correctly only recognize + after {}, but I'm wondering if it wouldn't
be more generally useful to make it accept these cases and do the
substitution in the correct word. I haven't actually implemented this
yet but I don't see any particular barrier to doing so. Alternatively
we could add another command, like say -mexec or something, that had
this behavior to avoid compatibility problems.


(lavender and smoky teal)

David A. Holland

Home | Main Index | Thread Index | Old Index