当 bash 遇到未知命令(单词?)时,它会执行以下操作:
The program 'hello' can be found in the following packages:
* hello
* hello-debhelper
Try: sudo apt-get install <selected package>
Run Code Online (Sandbox Code Playgroud)
我想知道的是这是如何完成的,所以我可以编辑它或在它之前添加一些东西来交叉检查来自本土词典的未知单词,该词典将有短语:回复对,然后可以发送到输出。
我为周围没有足够的寻找而感到内疚..但是我尝试挖掘的少数 bash 指南对此一无所知。也许我看错了地方……有什么指点吗?
是的,我正在这样做,所以每次我在程序失败时键入 wtf 时,我都希望得到一些好的东西……
gle*_*man 21
查看您/etc/bash.bashrc的command_not_found_handle函数定义。
如果您想删除该行为,请将其放在您的 .bashrc 中
[[ $(type -t command_not_found_handle) = "function" ]] &&
unset -f command_not_found_handle
Run Code Online (Sandbox Code Playgroud)
如果你想自定义,你可以做
# see http://stackoverflow.com/questions/1203583/how-do-i-rename-a-bash-function
alias_function() {
eval "${1}() $(declare -f ${2} | sed 1d)"
}
alias_function orig_command_not_found_handle command_not_found_handle
command_not_found_handle() {
command=$1
shift
args=( "$@" )
do your stuff before
orig_command_not_found_handle "$command" "${args[@]}"
do your stuff after
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2412 次 |
| 最近记录: |