在 dockerfile 运行 指令中转义带有特殊字符和单引号的字符串

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

我正在尝试将行附加到 VS Code devcontainer 的 Dockerfile 中的 .bashrc。但是我无法按原样保留字符串。

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

我最近的尝试看起来像这样,但我已经尝试了几个使用反引号等的不同变体。

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

因为Dockerfile中的echo\e解释为^[(ESC字符),所以需要双重转义:

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