Sometimes I needed to evaluate information output to stderr in a bash script, but how to capture that output?
[SOLUTION]
Luckily, I stumbled over a comment on "stackoverflow" about "redirecting stderr to a variable in a bash script".
The solution is as follows:
Redirect stderr to stdout and redirect stdout to /dev/null.
In Bash-speak, that is:
Code: Select all
cmd="whatever command you want to execute"
ERROR=$($cmd 2>&1 >/dev/null)
echo $ERROR