0

Is there a way to supress the command output for git if I use backticks in my shell script? Here is my current code:

OUT=$(git status > /dev/null)

Thanks :)

Morph
  • 173
  • 2
  • 5
  • 15

2 Answers2

7

I think what you're wanting is to suppress the stderr but not the stdout since you still want the value. You could do this instead:

OUT=$(git status 2>/dev/null)
konsolebox
  • 72,135
  • 12
  • 99
  • 105
1

In case some output is going to standard error:

OUT=$(git status > /dev/null 2>&1; echo $?)

Of course, this does leave open the question: what is it you want to capture in OUT?

[EDIT] The above will put the return code of git into $OUT.

lurker
  • 56,987
  • 9
  • 69
  • 103