So I'm running commands in a bash shell script, and I want to ONLY capture error output in a variable. Any standard output I want suppressed.
So far what I have definitely isn't working. So I'm trying to come up with a better idea, and struggling to find an answer.
Here's a code sample:
ERROR=$(svn switch "$NEW_URL" --accept postpone 1>/dev/null 2>&1) &
Looks like everything is getting suppressed. Any help would be appreciated. Thanks.
It should be like that:
error=$({ echo "stdout"; echo "stderr" >&2; } 2>&1 >/dev/null)
echo "$error"
stderr
i.e. redirect stderr->stdout first and then redirect stdout to /dev/null to suppress stdout.
For your command it should be:
error=$(svn switch "$NEW_URL" --accept postpone 2>&1 >/dev/null)
You also need to remove & to avoid pushing your command in background.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With