I can't figure out how to escape the dollar sign in order to access a variable defined in an environment in docker, when executing the command from a makefile.
This is a minimal representation of my setup and I'm trying to echo /mypath
define create-test
so-test-$1:
docker run \
--rm \
-t \
--env SRC="/mypath" \
ubuntu:xenial \
/bin/bash -c "$2"
endef
$(eval $(call create-test,1,echo $SRC ))
$(eval $(call create-test,2,echo $$SRC ))
$(eval $(call create-test,3,echo $$$$SRC ))
$(eval $(call create-test,4,echo $$$$$$$$SRC ))
The outputs are
$ make so-test-1
docker run --rm -t --env SRC="/mypath" ubuntu:xenial /bin/bash -c "echo RC "
RC
$ make so-test-2
docker run --rm -t --env SRC="/mypath" ubuntu:xenial /bin/bash -c "echo RC "
RC
$ make so-test-3
docker run --rm -t --env SRC="/mypath" ubuntu:xenial /bin/bash -c "echo $SRC "
$ make so-test-4
docker run --rm -t --env SRC="/mypath" ubuntu:xenial /bin/bash -c "echo $$SRC "
6526SRC
I know the environment variable is set because it shows if I call env
in the container.
How should I escape the SRC variable so that it is expanded inside the shell run in the docker container?