You are basically pasting the file name into sh -c '...'
without any quoting. The string inside sh -c
after the substitutions made by find
needs to be valid sh
syntax, which means there can be no unquoted single quotes, parentheses, etc.
A more robust approach is to use -exec file {}
and pass all the output from find
to egrep
.
find . -type f -name "*.png" -exec file {} \; | egrep -o '^.*\d+,'
The placeholder token {}
gets replaced by find
with the filename currently being processed. When it is a lone token, find
can pass in any file name at all; but if you interpolate it into a longer string, such as a shell command, you will need to ensure that any necessary quoting etc. is added somehow. That's messy, so usually you will want to find a solution where you don't need to do that.
(As pointed out in comments to the other answer, -exec sh -c 'file "$1"' _ {} \;
is another way to accomplish that; this generalizes to arbitrarily complex shell commands. If your find
supports exec {} \+
you want to add a simple loop: -exec sh 'for f; do file "$f"; done' _ {} \+
-- incidentally, the _
is a dummy placeholder for $0
.)