title: Bash script - For loop multiple arguments and awk
body: <p>I'm trying to write a BASH script for patching my CentOS servers. My goal is that when I run the script, it outputs the package name, the currently installed version, and new package version. Something like this:</p>
  
  <pre><code>nspr.x86_64 / 4.8.8-3.el6 / 4.8.9-3.el6_2
  </code></pre>
  
  <p>This way, if I ever need to downgrade because a package broke something, I have a record of this.</p>
  
  <p>The command <code>yum check-update</code> command gives me the 1st piece of information (the package name) and the 3rd piece of information (the new version) listed above, and I can use <code>awk</code> to separate the two. It's easy after that; just run <code>rpm -q {package}</code> to get the 2nd piece of information, then concatenate them.</p>
  
  <p>However, I'm running into trouble with the <code>for</code> loop in my code. I need to pass multiple arguments into the loop (the package name and newer version) so I can <code>echo</code> them later.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>for package in `/usr/bin/yum --cacheonly --noplugins check-update | awk '{print $1, $2}'`;
  do
      OLD_VER=`rpm -q ${package}` # ${package} should actually be $1 from the awk statement above
  
      NEW_VER=${2} # This is $2 from the awk statement above
  
      echo "${package} / ${OLD_VER} / ${NEW_VER}"
  done
  </code></pre>
  
  <p>Pardon the obvious errors in the code; I'm new to BASH scripting. My confusion mostly stems from awk; I'm not very familiar with it, nor how it interacts with a BASH script. However, I think it's clear what I'm trying to do. Does <code>package</code> get passed as an array? Is there a better way to do this?</p>