如何自动安装 bash 提示我安装的程序?

Tim*_*Tim 6 bash software-installation

我在考虑这个输出的用例:

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

我怎样才能让它提示我安装那个包?例如它会输出这个:

The program 'tiger' is currently not installed. You can install it by typing:
sudo apt-get install tiger
# Confirmation can go here
[sudo] password for tim:
The following NEW packages will be installed
  tiger tripwire
0 to upgrade, 11 to newly install, 0 to remove and 0 not to upgrade.
Need to get 8,416 kB of archives.
After this operation, 26.5 MB of additional disk space will be used.
Do you want to continue? [Y/n]  # and/or confirmation can go here
Run Code Online (Sandbox Code Playgroud)

我不想自己运行它。我怎样才能让它自动执行,并给我不安装的选项?

Flo*_*sch 15

如果您将环境变量设置COMMAND_NOT_FOUND_INSTALL_PROMPT1,例如

export COMMAND_NOT_FOUND_INSTALL_PROMPT=1
Run Code Online (Sandbox Code Playgroud)

你会被问到是否要安装这个包:

me@myhost:~$ tiger
The program 'tiger' is currently not installed. You can install it by typing:
sudo apt-get install tiger
Do you want to install it? (N/y)
Run Code Online (Sandbox Code Playgroud)

如果你回答y它会运行

sudo apt-get install tiger
Run Code Online (Sandbox Code Playgroud)

请参阅如何设置环境变量?关于如何设置环境变量。

  • 非常好!这是在哪里记录的?我不得不检查 `/usr/lib/python3/dist-packages/CommandNotFound/CommandNorFound.py` 的源代码,它由 `usr/lib/command-not-found` 调用,它是命令调用时调用的脚本没有找到。它似乎是一个 Ubuntu 功能(我的 Debian 上没有它)。它是否在 Ubuntu 文档中的某处提及?另外,为什么不能将 `Y` 设为默认值?如果您希望所有用户都使用它,只需将其设置在 `~/.profile` 或 `/etc/profile` 中。 (3认同)