1

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
The Fool
  • 16,715
  • 5
  • 52
  • 86
  • The cleanest solution would be storing the two lines in a `histsearch_binds.sh` file and concatenating this to the end of `.bashrc` with : `RUN cat histsearch_binds.sh >> /home/local-user/.bashrc` – Léa Gris Oct 24 '21 at 17:29
  • Please, see https://stackoverflow.com/questions/1030182/how-do-i-change-bash-history-completion-to-complete-whats-already-on-the-line – Arnaud Valmary Oct 24 '21 at 17:42
  • How does this solve my problem @ArnaudValmary? – The Fool Oct 24 '21 at 17:44
  • 2
    @TheFool Instead of modifying `.bashrc`, add a `/home/local-user/.inputrc` file on your image – Arnaud Valmary Oct 24 '21 at 18:04
  • @ArnaudValmary, it works fine in the bashrc, this question is about escaping the string. Since it needs to be echoed. I had the same problem with any other file such as .inputrc. – The Fool Oct 24 '21 at 19:27
  • @LeaGris : Why modifying .bashrc on the fly? One could include the correct .bashrc into the container. – user1934428 Oct 25 '21 at 09:22
  • @user1934428 or one doesnt want to use an extra COPY instruction and create unwanted extra layers as side effect nor clutter the local system with extra files in order to build a dev container. – The Fool Oct 25 '21 at 09:27
  • @ArnaudValmary this happens when I do it in .inputrc, it breaks something `source /my-project/.venv/"": history-search-forwardin/activate bash: /my-project/.venv/:: No such file or directory` . Working fine with bashrc for some reason – The Fool Nov 02 '21 at 11:37

1 Answers1

1

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
Philippe
  • 20,025
  • 2
  • 23
  • 32