Is it possible to get "find -exec" expand backticks for each file found?
Here's a command that works fine:
echo Blah: `stat -c %a .`
Is it possible to get find -exec
to execute this same thing for every file found, with {}
in place of .
?
Solution 1:
The best way to do that is to use positional parameters. And $()
is preferred for command substitution ove backticks because it's more readable (isn't confused with single quotes) and can be easily nested without having to do a lot of escaping.
find . -exec bash -c 'echo Blah: $(stat -c %a "$@")' _ {} \;
The underscore is a placeholder for $0
.
Solution 2:
What for?
find ... -printf 'Blah: %m\n'
Or use bash -c
if you really have to:
find . -exec bash -c 'echo Blah: `stat -c %a {}`' \;