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 &>
?
&>
(as a redirection) is a bashism - either change your shebang to#!/bin/bash
or use the POSIX> /dev/null 2>&1
– steeldriver Jul 09 '20 at 18:54&>
is interpreted in a POSIX shell, at the very end. – ilkkachu Jul 09 '20 at 19:08