Ubuntu 22.04 apt连管道符 | 提示:apt does not have a stable CLI interface
•
2024-02-20
•
文章类别:
操作系统 & 服务器
•
阅读量:2833
在 Ubuntu 22.04 中终端内使用 apt 命令通过管道符 | 与其他命令组合执行时(例如:sudo apt search --names-only firefox | grep zh)提示警告:WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
。在终端内使用 | 连接多个命令,这就构成了一个脚本,因此会提示“在脚本中使用要注意(Use with caution in scripts)”
本文将介绍如何在 Ubuntu 22.04 系统内解决 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
警告。
警告原因
apt
命令设计的目的就是在终端内与人交互使用,它提供一个可读性强的输出,比如说进度条,但是有些输出是其他命令无法识别的,因此它没有提供一个稳定的命令行接口,即该警告:WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
。
解决方法
apt-get
与 apt-cache
为在脚本中使用而设计的,它提供机器可读的输出(可能对人不太友好)。它们提供一个稳定的、可解析的命令行接口。
把 apt 更换为 apt-get
或 apt-cache
即可解决该警告,具体要更换为 apt-get
和 apt-cache
中的哪一个,你需要查看命令的版主文档。
例如:
sudo apt search --names-only firefox | grep zh
修改为:
sudo apt-cache search --names-only firefox | grep zh
结语
本文从 apt
, apt-get
与 apt-cache
三个命令的区别方面介绍了如何在 Ubuntu 22.04 系统内解决 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
警告。
0 评论