Tired of figuring out how to redirect output and capture the values accordingly? This is definitely the recipe.
Use 1>&2
at the beginning of the command:
1>&2 echo "all goes into stderr, even for stdout"
Use 2>&1
at the beginning of the command:
2>&1 echo "all goes into stderr, even for stdout"
Use 2>
at the end and redirect to /dev/null
:
ret="$(echo "all goes into stderr, even for stdout" 2> /dev/null)"
Use 2>&1
and then redirect the stdout to /dev/null
:
ret="$(2>&1 echo "all goes into stderr, even for stdout" > /dev/null)"
Use &>
to /dev/null
:
echo "all goes into stderr, even for stdout" &> /dev/null
Use >
and 2>
to the desired output files. The former is the stdout
, the latter is stderr
(the one with 2):
echo "all goes into stderr, even for stdout" > ./stdout.log 2> ./stderr.log
That's all about shell output redirects.