I am trying to use the result printed from a parameterized MongoDB script file in a bash script.
The call looks like this:
mongo --quiet server/db --eval "a='b'" mongoscript.js
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:
b
foo
instead of just 'foo'
Thus, if I do
res=`mongo --quiet server/db --eval "a='b'" mongoscript.js`
res contains both lines.
I can of course solve this with
res=`mongo ... |tail -n 1`
but I am hoping there is a more general way to avoid this superfluous output.
Thanks!