bind
显示当前读取键和函数绑定,将键序列绑定到readline函数或宏,或设置readline变量.

语法

  bind [-m keymap] [-lpsvPSV] 
  bind [-m keymap] [-q function] [-u function] [-r keyseq] 
  bind [-m keymap] -f filename 
  bind [-m keymap] -x keyseq:shell-command 
  bind [-m keymap] keyseq:function-name or readline-command

每个非选项参数都是在.inputrc中出现的命令,但每个绑定或命令必须作为单独的参数传递; 例如,’’\ Cx \ Cr“:重新读取-init-file’。

选项

-m keymap   使用键映射作为后续绑定影响的键映射。
            可接受的键映射名称是 emacs, emacs-standard, emacs-meta, emacs-ctlx, vi,
            vi-move, vi-command, vi-insert. vi相当于vi-command; 
            emacs相当于emacs-standard.

-l           列出所有readline函数的名称.

-p           以可重新读取的方式显示readline函数名称和绑定.

-P           列出当前的readline函数名称和绑定.

-s           显示绑定到宏的readline键序列以及它们以这样的方式输出的字符串
             可以重新阅读.

-S           显示绑定到宏的readline键序列及其输出的字符串t.

-v           以可重新读取的方式显示readline变量名称和值.

-V           列出当前的readline变量名称和值.

-f filename  从filename中读取键绑定.

-q function  查询哪些键调用命名函数.

-u function  取消绑定绑定到指定函数的所有键.

-r keyseq   删除所有当前绑定的keyseq.

-x keyseq:shell-command   导致在输入keyseq时执行的shell命令。
            执行shell-command时,shell将READLINE_LINE变量设置为readline 
            行缓冲区的内容,将READLINE_POINT变量设置
            为插入点的当前位置。如果执行的命令更改了
            READLINE_LINE或READLINE_POINT 的值,则这些新值将反映在编辑状态中.

除非给出无法识别的选项或发生错误,否则返回值为0。

您可以通过在命令行按Ctrl-v确定键发出的字符序列,然后按您感兴趣的键。或者运行读命令,然后按下感兴趣的键,Control-c将从read builtin命令返回。

\e 是转义字符, 作为显示输出 ^[

bind是一个内部命令; 绑定键映射可以通过省略bind命令和外部单引号集来缩写.

实例

设置shell以在使用向上和向下箭头键时执行历史记录搜索。
这允许键入命令的一部分,然后使用箭头从历史记录中选择匹配的命令。
(默认情况下,向上和向下只会选择以前的命令而不与历史记录匹配。)

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

最后两个绑定确保左右键继续正常工作

bind 命令实例:

linux命令:bind '"\ej": "!#:$\e^"' "!#:$\e^"' '"\ej": bind bind '"\ej": "!#:$\e^"'rootopen.com
linux命令:bind '"\ej": "!#:$\e^"' "!#:$\e^"' '"\ej": bind bind '"\ej": "!#:$\e^"'rootopen.com
2019-02-12 21:16:29

linux命令:bind -x '"\er":READLINE_LINE=$(eval "$READLINE_LINE");READLINE_POINT=${#READLINE_LINE}' "$READLINE_LINE");READLINE_POINT=${#READLINE_LINE}' '"\er":READLINE_LINE=$(eval -x bind bind -x '"\er":READLINE_LINE=$(eval "$READLINE_LINE");READLINE_POINT=${#READLINE_LINE}'rootopen.com
linux命令:bind -x '"\er":READLINE_LINE=$(eval "$READLINE_LINE");READLINE_POINT=${#READLINE_LINE}' "$READLINE_LINE");READLINE_POINT=${#READLINE_LINE}' '"\er":READLINE_LINE=$(eval -x bind bind -x '"\er":READLINE_LINE=$(eval "$READLINE_LINE");READLINE_POINT=${#READLINE_LINE}'rootopen.com
2019-02-12 21:13:47

linux命令:bind -p | grep -F "\C" "\C" -F grep | -p bind bind -p | grep -F "\C"rootopen.com
linux命令:bind -p | grep -F "\C" "\C" -F grep | -p bind bind -p | grep -F "\C"rootopen.com
2018-01-23 18:51:48

linux命令:bind '"\e[24~"':"\"ps -elF;df -h;free -mt;netstat -lnpt;who -a\C-m""" -a\C-m""" -lnpt;who -mt;netstat -h;free -elF;df '"\e[24~"':"\"ps bind bind '"\e[24~"':"\"ps -elF;df -h;free -mt;netstat -lnpt;who -a\C-m"""rootopen.com
linux命令:bind '"\e[24~"':"\"ps -elF;df -h;free -mt;netstat -lnpt;who -a\C-m""" -a\C-m""" -lnpt;who -mt;netstat -h;free -elF;df '"\e[24~"':"\"ps bind bind '"\e[24~"':"\"ps -elF;df -h;free -mt;netstat -lnpt;who -a\C-m"""rootopen.com
2018-02-27 00:46:48

linux命令:bind 'set match-hidden-files off' off' match-hidden-files 'set bind bind 'set match-hidden-files off'rootopen.com
linux命令:bind 'set match-hidden-files off' off' match-hidden-files 'set bind bind 'set match-hidden-files off'rootopen.com
2018-03-01 22:35:48

linux命令:bind '"\C-h": "\`fc\ \-s\`"' \-s\`"' "\`fc\ '"\C-h": bind bind '"\C-h": "\`fc\ \-s\`"'rootopen.com
linux命令:bind '"\C-h": "\`fc\ \-s\`"' \-s\`"' "\`fc\ '"\C-h": bind bind '"\C-h": "\`fc\ \-s\`"'rootopen.com
2018-06-04 23:08:48

linux命令:bindkey ^l at "#" log on bindkey ^o at "#" log off off log "#" at ^o bindkey on log "#" at ^l bindkey bindkey ^l at "#" log on bindkey ^o at "#" log offrootopen.com
linux命令:bindkey ^l at "#" log on bindkey ^o at "#" log off off log "#" at ^o bindkey on log "#" at ^l bindkey bindkey ^l at "#" log on bindkey ^o at "#" log offrootopen.com
2018-03-04 03:13:48

linux命令:bindkey ^f at "#" kill kill "#" at ^f bindkey bindkey ^f at "#" killrootopen.com
linux命令:bindkey ^f at "#" kill kill "#" at ^f bindkey bindkey ^f at "#" killrootopen.com
2018-03-22 10:28:48

linux命令:bind '"\C-l":"ls -l\n"' -l\n"' '"\C-l":"ls bind bind '"\C-l":"ls -l\n"'rootopen.com
linux命令:bind '"\C-l":"ls -l\n"' -l\n"' '"\C-l":"ls bind bind '"\C-l":"ls -l\n"'rootopen.com
2018-02-20 15:50:48

linux命令:bind '"\t":menu-complete' '"\t":menu-complete' bind bind '"\t":menu-complete'rootopen.com
linux命令:bind '"\t":menu-complete' '"\t":menu-complete' bind bind '"\t":menu-complete'rootopen.com
2018-03-18 21:57:48

linux命令:bind -x '"\C-l":ls -l' -l' '"\C-l":ls -x bind bind -x '"\C-l":ls -l'rootopen.com
linux命令:bind -x '"\C-l":ls -l' -l' '"\C-l":ls -x bind bind -x '"\C-l":ls -l'rootopen.com
2018-03-13 18:07:48

linux命令:bind '"\C-e":"\eb `which \ef`\e\C-e"' \ef`\e\C-e"' `which '"\C-e":"\eb bind bind '"\C-e":"\eb `which \ef`\e\C-e"'rootopen.com
linux命令:bind '"\C-e":"\eb `which \ef`\e\C-e"' \ef`\e\C-e"' `which '"\C-e":"\eb bind bind '"\C-e":"\eb `which \ef`\e\C-e"'rootopen.com
2018-03-03 21:29:48

linux命令:bind -x '"\C-p"':pwd '"\C-p"':pwd -x bind bind -x '"\C-p"':pwdrootopen.com
linux命令:bind -x '"\C-p"':pwd '"\C-p"':pwd -x bind bind -x '"\C-p"':pwdrootopen.com
2017-12-30 15:35:48

linux命令:bind -P -P bind bind -Prootopen.com
linux命令:bind -P -P bind bind -Prootopen.com
2018-05-11 11:22:48

linux命令:bind '"\ee": "\C-asudo \C-e"' \C-e"' "\C-asudo '"\ee": bind bind '"\ee": "\C-asudo \C-e"'rootopen.com
linux命令:bind '"\ee": "\C-asudo \C-e"' \C-e"' "\C-asudo '"\ee": bind bind '"\ee": "\C-asudo \C-e"'rootopen.com
2018-01-19 03:12:48

linux命令:bind '"\C-l": "\C-u cat <<EOT | pbcopy \n \C-y \nEOT\n"' \nEOT\n"' \C-y \n pbcopy | <<EOT cat "\C-u '"\C-l": bind bind '"\C-l": "\C-u cat <<EOT | pbcopy \n \C-y \nEOT\n"'rootopen.com
linux命令:bind '"\C-l": "\C-u cat <<EOT | pbcopy \n \C-y \nEOT\n"' \nEOT\n"' \C-y \n pbcopy | <<EOT cat "\C-u '"\C-l": bind bind '"\C-l": "\C-u cat <<EOT | pbcopy \n \C-y \nEOT\n"'rootopen.com
2018-06-07 03:06:48

linux命令:bind -P | grep -v "is not" | sed -e 's/can be found on/:/' | column -s: -t -t -s: column | on/:/' found be 's/can -e sed | not" "is -v grep | -P bind bind -P | grep -v "is not" | sed -e 's/can be found on/:/' | column -s: -trootopen.com
linux命令:bind -P | grep -v "is not" | sed -e 's/can be found on/:/' | column -s: -t -t -s: column | on/:/' found be 's/can -e sed | not" "is -v grep | -P bind bind -P | grep -v "is not" | sed -e 's/can be found on/:/' | column -s: -trootopen.com
2018-02-20 01:49:48

linux命令:bind '"<ctrl+v><functionKey>":"command\n"' '"<ctrl+v><functionKey>":"command\n"' bind bind '"<ctrl+v><functionKey>":"command\n"'rootopen.com
linux命令:bind '"<ctrl+v><functionKey>":"command\n"' '"<ctrl+v><functionKey>":"command\n"' bind bind '"<ctrl+v><functionKey>":"command\n"'rootopen.com
2018-03-24 05:04:48

linux命令:bind '"\e[A": history-search-backward' && bind '"\e[B": history-search-forward' && bind '"\eOA": history-search-backward' && bind '"\eOB": history-search-forward' history-search-forward' '"\eOB": bind && history-search-backward' '"\eOA": bind && history-search-forward' '"\e[B": bind && history-search-backward' '"\e[A": bind bind '"\e[A": history-search-backward' && bind '"\e[B": history-search-forward' && bind '"\eOA": history-search-backward' && bind '"\eOB": history-search-forward'rootopen.com
linux命令:bind '"\e[A": history-search-backward' && bind '"\e[B": history-search-forward' && bind '"\eOA": history-search-backward' && bind '"\eOB": history-search-forward' history-search-forward' '"\eOB": bind && history-search-backward' '"\eOA": bind && history-search-forward' '"\e[B": bind && history-search-backward' '"\e[A": bind bind '"\e[A": history-search-backward' && bind '"\e[B": history-search-forward' && bind '"\eOA": history-search-backward' && bind '"\eOB": history-search-forward'rootopen.com
2018-02-16 13:08:48

Linux的Bash命令行(A-Z排序)