【问题标题】:How to loop over piped lines and use lines as variable in bash?如何在管道上循环并将行用作bash中的变量?
【发布时间】:2014-09-24 08:46:01
【问题描述】:

当我的服务器显示*** System restart required *** 时,我想知道是否有任何非常紧急的事项需要更新。为此,我可以按顺序执行以下操作:

cat /var/run/reboot-required.pkgs
# Which outputs something like:
#    linux-image-3.13.0-36-generic
#    linux-base
#    dbus

aptitude changelog <package-name> | grep urgency=high
# If there is no output, there is no patch waiting with a high urgency

我现在想将这两个命令合并为一个,以便它自动循环第一个命令的输出,并将该行用作&lt;package-name&gt;

有人知道我该怎么做吗?

【问题讨论】:

    标签: bash loops pipe


    【解决方案1】:

    你可以使用xargs:

    xargs aptitude changelog < /var/run/reboot-required.pkgs | grep ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-02
      • 2017-06-15
      相关资源
      最近更新 更多