How to bind the 'Enter key' in Bash readline?

。_饼干妹妹 提交于 2019-12-01 20:49:31

问题


So I learned how to use bind yesterday.

By typing Ctrl+v followed by a key in the terminal, I get a raw character that represents the key. For example: Ctrl+v followed by Esc returns ^[.

My question is, how can I bind the "enter key". The Enter Key returns ^M but when I type the command

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

pressing the enter key does not result in foobar being typed in my terminal.


回答1:


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

binds Escape-Enter, not Enter. You just want

bind '"^M":"foobar"'

^M must be the actual control character, not ^ and M. A little easier to type is

bind '"\C-M":"foobar"'



回答2:


$ alias ^M='echo foobar'
$ ^M
foobar


来源:https://stackoverflow.com/questions/20151416/how-to-bind-the-enter-key-in-bash-readline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!