pass an argument with escape characters to a script with docker exec

  bash, docker, escaping, shell

I would like to pass the variable $styled to a script inside a docker container.

The docker command would look something like

docker exec container_name "/bin/bash -c cd /where/the/script/is && ./ $styled"

the would look like this

echo -e $1

the variable $styled contains escape characters, so lets say it is:


On my local computer i can pass the variable to a local without any issues, unfortunately it doesn’t work while using dockers exec.

the error message is something like:

./ x1b[7mFF1SOME_TEXTx1b[27m: no such file or directory": unknown

I am pretty sure it has to do with how escaping works, single quotes, double quotes and so on, but I am simply confused by all those layers.

I also tried:

docker exec container_name "/bin/bash -c 'cd /where/the/script/is && ./ '$P'"

which results in

stat /bin/bash -c 'cd /where/the/script/is && ./ 'x1b[7mSOME_TEXTx1b[27m': no such file or directory"

Source: Docker Questions