title: Order mismatch between stdout and stderr in bash
body: <p>I am executing a bash command in interactive shell as 
  <code>./somescript.sh</code></p>
  
  <p>It gives output as </p>
  
  <pre><code>OS platform is: linux2
  killall agent
  agent: no process killed
  </code></pre>
  
  <p>where third line comes from stderr.</p>
  
  <p>But when I execute in the subshell as</p>
  
  <pre><code>var=$('./somescript.sh' 2&gt;&amp;1)
  agent: no process killed
  OS platform is: linux2
  killall agent
  </code></pre>
  
  <p>Why did the agent: no process killed is printing in the first line now?
  How can I make it consistent to align both of them?</p>
  
  <p>Edit:
  However when I did ,
  <code>var=$('./somescript.sh' 1&gt;&amp;2)</code> 
  I can see that it's giving the output in correct order in bash debug mode. But it's not getting stored in the variable var. </p>