0

I'm looking at a pre-commit git hook script. Here's the part I'm struggling with:

#!/bin/sh
...
testcmd="go test -race ${godirs} "
failed=
${testcmd} &> /dev/null # problematic line
if [ $? -ne 0 ] ; then
    failed=1
    ${testcmd}
fi

godirs is a list of folders built earlier in the script. When I run this, I see the output of testcmd running slightly delayed (it prints over my next prompt). It seems that &> isn't redirecting 2 outputs. It's running the go test in the background and not even redirecting output.

I'm no good at shell scripting. I know I could rewrite it as > /dev/null 2> /dev/null but this is a learning opportunity. How can I fix this so I can still use &>?

0 Answers0