0

I'm trying to run the following command from a tutorial:

docker run --rm -v $(pwd):/check --network des mongo:4.2 bash -c \
"mongorestore -hmongo -u moAdmin -p <PWD> --gzip --archive=/check/test.gz  --nsInclude='test.*' --drop"

The problem is that the password contains ! and | and I'm not sure how to correctly escape these inside the already used double quotes.

Thanks for your help!

2

You could temporarily turn off history expansion:

set +H
docker run --rm -v $(pwd):/check --network des mongo:4.2 bash -c \
"mongorestore -hmongo -u moAdmin -p <PWD> --gzip --archive=/check/test.gz  --nsInclude='test.*' --drop"
set -H

Or you could just escape the character:

docker run --rm -v $(pwd):/check --network des mongo:4.2 bash -c \
"mongorestore -hmongo -u moAdmin -p P@assword\! --gzip --archive=/check/test.gz  --nsInclude='test.*' --drop"

You could store it in a variable:

password='P@ssword!'
docker run --rm -v $(pwd):/check --network des mongo:4.2 bash -c \
"mongorestore -hmongo -u moAdmin -p \"$password\" --gzip --archive=/check/test.gz  --nsInclude='test.*' --drop"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.