When working with a bash script, you may encounter the error message Unexpected token ILLEGAL
#!/bin/bash
value="White Spaced String"
mongo --verbose localhost:27017/myDB --eval 'db.ips.update({"id":"id"}, { $push: { "key": {"key":"'$value'"}}})'
However, if you remove the whitespaces in the variable declaration like this:
#!/bin/bash
value="NonWhiteSpacedString"
mongo --verbose localhost:27017/myDB --eval 'db.ips.update({"id":"id"}, { $push: { "key": {"key":"'$value'"}}})'
If you still want to keep the whitespaces and encounter issues, one idea to work around it is by using:
value="${value// /\\ }"
This command substitutes whitespaces with \ escape signs and a whitespace.
Another workaround that works but changes the whitespaces is:
value="${value// /_}"