4

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.

1
  • 2
    This is a duplicate of this question Commented Apr 7, 2016 at 22:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.