如何使用 apt-get 获取待升级的软件包列表?

Tra*_*ggs 9 apt software-updates

我很好奇是否有一种脚本友好的方法来计算apt list --upgradeable. 这会产生一个很好的输出,每行只有一个升级候选,非常易于解析。但是,apt还警告:

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Run Code Online (Sandbox Code Playgroud)

所以我觉得我应该用venerableapt-get来代替。不幸的是,它的输出看起来像这样:

apt-get -s --no-download dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  dbus libdbus-1-3
The following packages will be upgraded:
  bash gcc-8-base gpgv libedit2 libgcc1 libprocps7 libpsl5 libselinux1 libsemanage-common libsemanage1 libsepol1 libsqlite3-0 libstdc++6 perl-base
  procps publicsuffix rsyslog twigpilot-core
18 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
...
Run Code Online (Sandbox Code Playgroud)

这是很难解析的。所以我希望有某种方式来获得apt-get更新来打印更简洁的列表apt

Ark*_*zyk 5

我不经常使用 Ubuntu,但是这个怎么样:

$ apt-get -s --no-download dist-upgrade -V | grep '=>' | awk '{print$1}'
Run Code Online (Sandbox Code Playgroud)

它每行打印一个包。如中所述man apt-get

   -V, --verbose-versions
       Show full versions for upgraded and installed packages. Configuration Item: APT::Get::Show-Versions.
Run Code Online (Sandbox Code Playgroud)