0

I am writing a portable procedure (i.e. I am not using dpkg) in a Bash script that ensures that certain program versions are available. I can get the version of indent in the following way:

version_indent="$(echo "$(indent --version)" | cut -d" " -f3)"

I don't understand why I can't get the version of astyle in a similar way:

version_astyle="$(echo "$(astyle --version)" | cut -d" " -f4)"

When I do the former, I get the actual version; when I do the latter, I get the full string returned by astyle printed to the terminal and nothing saved to the variable. What's going wrong?

d3pd
  • 7,935
  • 24
  • 76
  • 127
  • What does the output of `astyle --version` look like? – Tom Fenech Nov 16 '15 at 17:17
  • 6
    Probably `astyle --version` returns the result via stderr, not stdout. See http://stackoverflow.com/a/33694394/1983854 for someting similar. Basically, just redirect stderr to stdin by saying `astyle --version 2>&1`. – fedorqui Nov 16 '15 at 17:17
  • 4
    Sounds like @fedorqui is onto something there. Also I think you can change `echo "$(astyle --version)"` to just `astyle --version`. – Tom Fenech Nov 16 '15 at 17:20
  • @TomFenech in fact I was astonished checking how uncanonical the output of `--version` is. Some send it through `stderr` and some through `stdout`. Uhms, not nice. – fedorqui Nov 16 '15 at 17:21
  • 3
    The `echo $(...)` wrapping is entirely pointless (and costly). – Etan Reisner Nov 16 '15 at 17:31
  • 1
    @TomFenech This seems to work for me: `version_astyle="$(astyle --version 2>&1 | cut -d" " -f4)"` Is this the most reasonable approach? – d3pd Nov 16 '15 at 17:48
  • 1
    @d3pd looks good to me – Tom Fenech Nov 16 '15 at 17:51
  • Similar question: https://stackoverflow.com/questions/13483443/why-does-java-version-go-to-stderr – glenn jackman Nov 16 '15 at 20:08

0 Answers0