如何在 Debian 上实施软件包安装建议?

Joe*_*hew 28 bash ubuntu debian autocomplete command-not-found

我注意到在 Ubuntu 上,如果我输入以下内容:

mc
Run Code Online (Sandbox Code Playgroud)

它没有安装,我收到以下消息:

The program 'mc' is currently not installed. You can install it by typing: sudo apt-get install mc
Run Code Online (Sandbox Code Playgroud)

但是在 Debian 中,这是不可用的。它只是给出了“-bash:/usr/bin/mc:没有这样的文件或目录”消息。如何在 Debian 的 bash 命令行中实现相同的功能?是的,我知道如果我想要包建议,我可以简单地使用apt-cache search进行正则表达式搜索。但是,我希望在输入程序名称时立即得到更简单的建议。

根据讨论,该功能由包command-not-found 提供。但是,即使在安装它并安装 bash-completion 包之后,这在 Debian bash shell 上也不可用。

Joe*_*hew 29

安装command-not-found没有开始为未安装的软件包提供建议的原因是我在安装过程中错过了来自 dpkg 的一个小通知。

一个应该在运行update-command-not-found后立即运行命令apt-get install command-not-found。实际上 dpkg 会提示运行此命令。

  • 我还必须在运行 `update-command-not-found` 之前运行 `apt-get update`,然后打开一个新的 bash 会话或 `source /etc/bash.bash.rc`。 (2认同)

les*_*ana 10

debian 包似乎不完整。自述文件说你应该/etc/bash_command_not_found在你的.bashrc. 奇怪的是,该文件未包含在包中。

debiancommand-not-found基于ubuntu 包。ubuntu 包在这方面似乎更完整。

bash_command_not_found ubuntu 版本的内容

command_not_found_handle() {
  if  [ -x /usr/lib/command-not-found ]; then
     /usr/lib/command-not-found -- "$1" 
     return $?
  else
     return 127
  fi        
}
Run Code Online (Sandbox Code Playgroud)

将这些行添加到您的~/.bashrc(或/etc/bash.bashrc) 中,该command-not-found功能应该可以正常工作。

  • README 不正确,Debian 不使用该文件。该处理程序包含在 /etc/bash.bashrc 中(至少在 Debian 9 中),该处理程序在 Bash 交互式 shell 启动时自动运行。 (2认同)