Consider the following:
/tmp/tmp.DkL0R4v7RR$ find . -regex '\./spam' -o -regex '\./eggs'
./spam
./eggs
/tmp/tmp.DkL0R4v7RR$ find . -regex '\./spam' -o -regex '\./eggs' -exec ls \{} \;
./eggs
/tmp/tmp.DkL0R4v7RR$ find . -regex '\./spam' -o -regex '\./eggs' | xargs ls
./eggs ./spam
Why does the appended -exec
alter the behaviour so that only the second regex is matched?
find . "(-regex '\./spam' -o -regex '\./eggs')" -exec ls \{} \;
but to no avail. It’s not entirely clear to me why it has to be escaped like that, but … well, thanks, anyway – karlsebal Apr 06 '22 at 10:37(
and)
need to be escaped because they're part of the shell syntax (for starting subshells and other uses),{}
doesn't need to be escaped in some shells, though. – muru Apr 06 '22 at 10:48'('
and\)
need to be single arguments on the command line. – karlsebal Apr 06 '22 at 10:52find
is not likesed
(orawk
) where you can provide code as a string and the tool parses it.find
expects operands as separate arguments. It performs neither word splitting nor quote removal; these are jobs of the shell. – Kamil Maciorowski Apr 06 '22 at 11:54