kramer65
kramer65

Reputation: 53873

How to loop over piped lines and use lines as variable in bash?

When my server says *** System restart required *** I want to know whether there are any highly urgent matters that need updated. For this I can do the following in order:

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

I now want to combine these two commands into one so that it automatically loops over de output of the first command, and uses that line as <package-name>.

Does anybody know how I can do this?

Upvotes: 1

Views: 62

Answers (1)

hek2mgl
hek2mgl

Reputation: 158040

You can use xargs:

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

Upvotes: 1

Related Questions