与 apt-get 相比,管道 apt 输出的安全隐患是什么?

与 apt-get 相比,管道 apt 输出的安全隐患是什么?

我尝试安装所有 python3 软件包,这样我就不必每次都手动进入终端安装。然而,由于一些依赖性问题,apt 拒绝继续:

sonic@boomboom:~$ sudo apt install python3*
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'python3-trufont' for glob 'python3*'
(Long list of packages)
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python3-chargebee : Conflicts: python3-chargebee2 but 2.7.3-1 is to be installed
 (Long list of packages)
E: Unable to correct problems, you have held broken packages.

因此,我决定编写一个简短的脚本来解析 的输出apt,并自动安装与我的 glob 匹配的所有软件包(除了那些可卸载的软件包)。首先,我尝试grep仅过滤不需要的包:

sonic@boomboom:~$ sudo apt install python3* | grep 'Conflicts:'

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

 python3-chargebee : Conflicts: python3-chargebee2 but 2.7.3-1 is to be installed
 python3-chargebee2 : Conflicts: python3-chargebee but 1.6.6-1 is to be installed
 (Long list of packages)
E: Unable to correct problems, you have held broken packages.

Grep 确实有效,但会弹出一个警告,有趣的是,当我使用它时,它不会出现apt-get

sonic@boomboom:~$ sudo apt install python3* | grep 'Conflicts:'
 python3-chargebee : Conflicts: python3-chargebee2 but 2.7.3-1 is to be installed
 python3-chargebee2 : Conflicts: python3-chargebee but 1.6.6-1 is to be installed
 (Long list of packages)
E: Unable to correct problems, you have held broken packages.

除了警告消息之外,输出完全相同。apt促使开发人员添加警告的管道的安全隐患是什么?为什么apt-get不给出同样的警告?我相信这两个命令或多或少是相同的。

答案1

如果您不尝试解析其输出,则apt应该可以安全使用。发出警告的主要原因是旨在apt用于交互式使用:

apt为包管理系统提供高级命令行界面。它旨在作为最终用户界面,与更专业的 APT 工具(如apt-get(8)和 )相比,默认情况下启用一些更适合交互式使用的选项apt-cache(8)

如果它的输出不是终端,它会认为它没有被交互使用并显示警告。按照你的情况,没有危险。

相关内容