Weird result of initiating a variable with the output of 'git describe'

0

For some reason this assignment: OUT=$(git describe HEAD) prints to the stdout (for example): fatal: No names found, cannot describe anything.

Is this a normal behavior? Why doesn't this happen with other commands?

andrey

Posted 2015-07-15T20:28:44.330

Reputation: 145

Answers

1

That's actually stderr output, not stdout. When running a command from an interactive terminal, both stdout and stderr are set to go to the terminal.

If you wanted the stderr output in your variable (which you probably don't, but anyway), redirect it to stdout like this:

OUT=$(git describe HEAD 2>&1)

Or if you didn't want the person running your script to see that stderr output, throw it away like this:

OUT=$(git describe HEAD 2>/dev/null)

Spiff

Posted 2015-07-15T20:28:44.330

Reputation: 84 656