title: Use result from mongodb in shell script
body: <p>I am trying to use the result printed from a parameterized MongoDB script file in a bash script.</p>
  
  <p>The call looks like this:</p>
  
  <pre><code>mongo --quiet server/db --eval "a='b'" mongoscript.js
  </code></pre>
  
  <p>Inside mongoscript.js there is a print statement that prints the value 'foo' I want to use in my shell script. The problem is that when I execute above statement I get:</p>
  
  <pre><code>b
  foo
  </code></pre>
  
  <p>instead of just 'foo'</p>
  
  <p>Thus, if I do</p>
  
  <pre><code>res=`mongo --quiet server/db --eval "a='b'" mongoscript.js`
  </code></pre>
  
  <p>res contains both lines.</p>
  
  <p>I can of course solve this with </p>
  
  <pre><code>res=`mongo ... |tail -n 1`
  </code></pre>
  
  <p>but I am hoping there is a more general way to avoid this superfluous output.</p>
  
  <p>Thanks!</p>