title: Bash script store command output into variable
body: <p>I have a problem concerning storing the output of a command inside a variable within a bash script.<br>
  I know in general there are two ways to do this</p>
  
  <p>either</p>
  
  <pre><code>foo=$(bar)
  # or
  foo=`bar`
  </code></pre>
  
  <p>but for the Java version query, this doesn't seem to work.</p>
  
  <p>I did:</p>
  
  <pre><code>version=$(java --version)
  </code></pre>
  
  <p>This doesn't store the value inside the var. It even still prints it, which really shouldn't be the case.</p>
  
  <p>I also tried redirecting output to a file but this also fails.</p>