3

I have a find command with multiple -exec arguments and would like the output (both stdout and stderr) for one of the commands to be suppressed. When I use &>/path/to/file, it sends the process to the background instead of redirecting output.

find /some/path -type f -exec sh -c 'scriptA.sh "$1"' _ "{}" \; -exec sh -c 'scriptB.sh "$1" &>/dev/null' _ "{}" \;

I found a way around it by using the command below (which also uses the '&' character), but I would like to know why it sends the process to the background instead of redirecting output like it normally would. So why does the command below work, but the one above does not?

find /some/path -type f -exec sh -c 'scriptA.sh "$1"' _ "{}" \; -exec sh -c 'scriptB.sh "$1" >/dev/null 2>&1' _ "{}" \;

Thanks!

2

The proper syntax to redirect is 2>&1. bash accepts the extended &> syntax, but the Bourne shell or ash variant you have invoked from find -exec does not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.