I'm creating a Docker container which needs to create a certain bash script. I use the following RUN sentence inside my Dockerfile:
RUN printf "#!/bin/bash\n \
# This is a bash comment inside the script\
ls -l" > /home/myuser/script.sh
It works well, but the resulting script is just:
#!/bin/bash
ls -l
So, bash comment is missing from the final file. I suspect that the reason is that Docker assumes that the line is a Dockerfile comment, but since it's enclosed inside double quotes, I think it's clear that's not the case.
Of course I could solve the issue by just including the full script in a single line, or placing it in an external file, but I think it should be possible to include bash comments inside a multiline, quoted string without this kind of problems. Any workaround? I've tried all kind of escapings, without success.