我如何在Ubuntu中教bash一些诅咒词?

当bash遇到一个未知的命令(单词?)时,它会这样做:

The program 'hello' can be found in the following packages: * hello * hello-debhelper Try: sudo apt-get install  

我想知道的是如何做到这一点所以我可以编辑它或在它之前添加一些东西来交叉检查本土词典中的未知单词,该单词将有短语:回复对然后可以发送到输出。

我很不满意它周围……但是我试过挖掘的几个bash指南没有任何关于此的东西。 也许我正在寻找错误的地方..任何指针?

是的,我这样做,所以每当我在程序失败时键入wtf,我想要一些好的东西扔给我…

/etc/bash.bashrc查找command_not_found_handle函数定义。

如果要删除该行为,请将其放在.bashrc中

 [[ $(type -t command_not_found_handle) = "function" ]] && unset -f command_not_found_handle 

如果你想自定义,你可以做到

 # 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 } 

这可能是有用的……

命令未找到的包可以为您提供神奇的响应。 我不确定是否可以自定义它,但它可能值得一看。

另一个做我认为你想要做的事情的选择是为你的.bashrc文件添加一个别名,当你输入’wtf’之类的东西时会打印一条消息:

 alias wtf='echo "chill out man"' 

将其添加到〜/ .bashrc文件中,然后执行: source $HOME/.bashrc

这样,只要在终端输入wtf就会打印一条消息。 您还可以将此别名调用为打印更详细消息或类似内容的脚本。 可能性是无止境!

此行为在系统范围的Bash配置文件/etc/bash.bashrc

 # if the command-not-found package is installed, use it if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found ]; then function command_not_found_handle { # check because cnf could've been removed in the meantime if [ -x /usr/lib/command-not-found ]; then /usr/bin/python /usr/lib/command-not-found -- "$1" return $? elif [ -x /usr/share/command-not-found ]; then /usr/bin/python /usr/share/command-not-found -- "$1" return $? else return 127 fi } fi 

要自定义它,只需在您自己的~/.bashrc覆盖此函数:

 function command_not_found_handle { echo "Sorry, smotchkiss, try again." } 

@ user606723,如果你想彻底摆脱这种行为:

 sudo apt-get remove command-not-found command-not-found-data 

如果这不起作用,试试这个:

 sudo apt-get purge command-not-found command-not-found-data 

如果你想恢复行为:

 sudo apt-get install command-not-found