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!

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .