title: Why does awk print the full line when using eval?
body: <p>I'm currently in the process of modifying a large BASH script which installs/checks a series of packages in a few different distros (mainly Redhat and Debian based).</p>
  
  <p>To handle some of the differences between the distros (e.g. rpm vs dpkg, yum vs apt, etc) I'm trying to load some variables with various command strings so that the script isn't full of <code>if debian then this, otherwise this</code> statements. However it appears that <code>awk</code> doesn't like being put inside an eval statement, and I can't figure out why.</p>
  
  <p><strong>Example</strong></p>
  
  <pre><code># Example dpkg --list output
  # ii  bash       4.1-2ubuntu3    The GNU Bourne Again SHell
  
  dpkg --list | grep 'bash'
  # Outputs bash entries in dpkg.
  
  cmd="dpkg --list | grep 'bash'"
  eval $cmd                                       
  # Outputs as expected, same as above.
  
  dpkg --list | awk '/^.i/ { print $2 }'
  # Outputs as expected, a list of package names.
  
  cmd="dpkg --list | awk '/^.i/ { print $2 }'"
  eval $cmd
  # Awk prints full output from dpkg for every line matching the regex.
  </code></pre>
  
  <p>In the code above, simply grepping for a given package works fine, and prints as expected, but when trying to generate a full list of package names using awk, the <code>print $2</code> appears to be ignored and simply prints the full line.</p>
  
  <p>Any ideas?</p>