My scenario is a little bit complex:
- I have an environment variable in my
Dockerfile
, which is a path:ENV ORACLE_HOME=/home/oracle
- I need to do some file manipulation later, so I am using sed
- Unfortunately I need to escape the path characters
\
for sed before I use the variable.
This is what I have:
ENV ORACLE_HOME=/home/oracle
ENV ORACLE_HOME_ESCAPED="$(printf '%q\n' "$ORACLE_HOME")"
RUN sed 's/.*pattern.*/\"-Dsomekey='${ORACLE_HOME_ESCAPED}'\"/' file
The RUN
line works fine if ORACLE_HOME
only contains simple characters.
My escaping command with printf
works properly in bash
, but it does not work in Dockerfie
.
Unfortunately, I only have GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
and there is no update for bash 4.4 so I am NOT able to use ${@Q}
notation. I use oraclelinux:7-slim
as a base image.
Any suggestion about what is wrong with the printf
?