title: Bash: Looping over multiple input sources (nesting "while read" loops?)
body: <p>I have a <code>query.sh</code> script which runs <code>dig</code> commands, performing a set of lookups from different DNS servers, which are currently given in a column in the single input file used (<code>sites.txt</code>).</p>
  
  <p>My goal is to modify this script to use a different input file, <code>dns_servers.txt</code>, to find the DNS servers to iterate through for each query.</p>
  
  <p>I'm not clear on where to start here. What do I need to do to be able to safely nest <code>while read</code> loops?</p>
  
  <hr>
  
  <h2>Current inputs:</h2>
  
  <h3>query.sh</h3>
  
  <pre><code>#!/bin/sh
  
  while read line;
  do
          set $line
          echo "SITE:" $1@$2
          /usr/sbin/dig +short -4 @$2 $1
          sleep 5
          exitStatus=$?
          echo "Exit Status: " $exitStatus
  done &lt; sites.txt
  </code></pre>
  
  <h3>sites.txt</h3>
  
  <p>Current format has a hostname and a DNS server to use for lookups against that hostname.</p>
  
  <pre><code>www.google.com 8.8.4.4
  </code></pre>
  
  <p>The intent is for the column with the DNS server to be ignored, and the contents of <code>dns_servers.txt</code> to be used instead.</p>
  
  <hr>
  
  <h2>Desired Inputs</h2>
  
  <h3>dns_servers.txt</h3>
  
  <pre><code>10.1.1.1
  12.104.1.232
  ...
  </code></pre>