I'm finding that when I use find's -or operator in combination with -exec, I don't get the result I expect. When searching for .cpp and .h files, the command works as expected if I don't use -exec:
find . -name '*.cpp' -or -name '*.h'
./file1.cpp
./file1.h
./file2.cpp
./file2.h
However, when I use -exec, only the .h files seem to be passed:
find . -name '*.cpp' -or -name '*.h' -exec echo '{}' \;
./file1.h
./file2.h
It works fine when I use the more generalized approach for returning the result:
echo $(find . -name '*.cpp' -or -name '*.h')
./file1.cpp ./file1.h ./file2.cpp ./file2.h
However, I'd like to know what I'm doing wrong with -exec, as it's often more convenient. I'm using Mac OSX 10.9, but the same issue occurs in a Cygwin terminal. What's going wrong here? How can I make -exec work the way I want?