I have a docker container I want to run and hand it over some passwords. One with an exclamation mark ! and the other one with an ampersand &. So I want to run this:

docker run -i -t --rm \ -e "LDAP_FILTER=(&(objectCategory=person)(objectClass=user)" \ -e "LDAP_PASS=Secret!Password" \ user-prefix/container-name 

That does not work. & gets replaced to {LDAP_FILTER} and the ! get truncated. I'm pretty sure I have to escape these. But \! and \& didn't work out.

3

2 Answers

I found a solution:

  • Using single-quotes instead of double-quotes
  • Escape the ampersand & to \&
  • Not escaping the exclamation mark !

so this works:

docker run -i -t --rm \ -e 'LDAP_FILTER=(\&(objectCategory=person)(objectClass=user)' \ -e 'LDAP_PASS=Secret!Password' \ user-prefix/container-name 

If you cannot use single-quotes for the entire string for some reason (e.g. variable expansion), this is probably the best solution: In bash, how do I escape an exclamation mark?

In summary: Use "'!'" around the exclamation mark:

echo "hello there"'!'" and goodbye" 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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