How to bind the Enter key in a Bash readline?

So, I found out how to use binding yesterday.

By typing Ctrl+ vfollowed by a key in the terminal, I get a raw character that represents the key. For example: Ctrl+ vfollowed by Escreturns ^[.

My question is how can I bind an input key. Enter key returns ^M, but when I type the command

bind '"\e^M":"foobar"'

pressing the enter key does not cause foobar to be entered into my terminal.

+4
source share
2 answers
bind '"\e^M":"foobar"'

binds Escape-Enter, not Enter. You just want

bind '"^M":"foobar"'

^M , ^ M.

bind '"\C-M":"foobar"'
+4
$ alias ^M='echo foobar'
$ ^M
foobar
0

All Articles