Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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