In a bash script, this won't work with Unexpected token ILLEGAL
#!/bin/bash
value="White Spaced String"
mongo --verbose localhost:27017/myDB --eval 'db.ips.update({"id":"id"}, { $push: { "key": {"key":"'$value'"}}})'
where as this works:
#!/bin/bash
value="NonWhiteSpacedString"
mongo --verbose localhost:27017/myDB --eval 'db.ips.update({"id":"id"}, { $push: { "key": {"key":"'$value'"}}})'
Any ideas ow to work around this? I tried:
value="${value// /\\ }" which will substitute whitespaces with \ escape signs and a whitespace. Yet, no success.
This does work, yet I want to preserve the whitespaces in my JSON in Mongo:
value="${value// /_}"
"which appear to not be escaping right