您可能想要的是覆盖bash的command-not-found处理程序.这是安装处理程序的标准Ubuntu安装中/etc/bash.bashrc中的部分:
...
# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found ]; then
function command_not_found_handle {
# check because c-n-f 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 $?
else
return 127
fi
}
fi
...
实际上,如果未找到命令,则使用该命令作为参数执行用户指定的程序.对于Ubuntu,它是一个Python程序,它检查用户键入的命令是否是可以安装的有效应用程序,如果是,则通知用户他/她可以安装它.
您可能想要做的是将它与命令和用法字符串的hashref进行比较,如果匹配则显示相应的一个.