Home > Mobile >  escaping a string with special characters and single quotes in a dockefile run instruction
escaping a string with special characters and single quotes in a dockefile run instruction

Time:10-25

I am trying to append to lines to the .bashrc in a Dockerfile for a VS Code devcontainer. But I am not able to preserve the string as they are.

bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

My most recent attempt looks like this, but I have already tried a couple different variants using backticks and so on.

RUN echo "bind '\"\\e[A\": history-search-backward'" >> /home/local-user/.bashrc \
 && echo "bind '\"\\e[B\": history-search-forward'" >> /home/local-user/.bashrc

CodePudding user response:

Because echo in Dockerfile interprets \e to ^[ (ESC character), so you need double escaping :

RUN echo "bind '\"\\\\e[A\": history-search-backward'" >> /home/local-user/.bashrc \
 && echo "bind '\"\\\\e[B\": history-search-forward'" >> /home/local-user/.bashrc
  • Related