Redirecting both STDOUT and STDERRsuggest change
File descriptors like
1 are pointers. We change what file descriptors point to with redirection.
1 points to
First we point
/dev/null then point
STDERR) to whatever
1 points to.
# STDERR is redirect to STDOUT: redirected to /dev/null, # effectually redirecting both STDERR and STDOUT to /dev/null echo 'hello' > /dev/null 2>&1
This can be further shortened to the following:
echo 'hello' &> /dev/null
However, this form may be undesirable in production if shell compatibility is a concern as it conflicts with POSIX, introduces parsing ambiguity, and shells without this feature will misinterpret it:
# Actual code echo 'hello' &> /dev/null echo 'hello' &> /dev/null 'goodbye' # Desired behavior echo 'hello' > /dev/null 2>&1 echo 'hello' 'goodbye' > /dev/null 2>&1 # Actual behavior echo 'hello' & echo 'hello' & goodbye > /dev/null
&> is known to work as desired in both Bash and Zsh.