2

Is it possible to store mongo output into a variable in shell script, below is the example query which prints decimal date

ex: 1489442900000

maxdate =$( echo mongo getmaxdate.js --quiet)

Any help is highly appreciated.

Thanks, Ashwin.

0

1 Answer 1

1

There should be no space between the variable name and the command during the assignment.

variable_name=$(command1 |command2 .....)

In your case:

maxdate=$( mongo getmaxdate.js --quiet)

Make sure to preserve the formatting of the output. if echo'ed Without double quote the whole content will show up in one line.

echo "$maxdate"
Sign up to request clarification or add additional context in comments.

1 Comment

actually it should be enclosed in backtick "$(echo mongo getmaxdate.js --quiet)" , this is working for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.