title: Problems in using the user-provided values of headers in wget command
body: <p>I am writing a simple bash shell script; which outputs the page-load time of url. The server responds with correct page only when it is requested with specific custom headers (FYI: absence of headers the default page is served by server. ) 
  The url to visit &amp; its headers are read from a config file (delimited by semi-colon)
  Sample entry: <a href="http://google.com/;User-Agent:XYZ" rel="nofollow">http://google.com/;User-Agent:XYZ</a> A;msisdn:98xxxxxxxx</p>
  
  <p>I did everything from reading the file to firing the wget command. </p>
  
  <p>However, looking at the output I found out that, headers string is not correctly passed (though I am building it correctly) to the wget command.
  On debugging further, I found out that bash/linux in-tern wrapping the whole headers string into single quotes and sending it to wget command due to which the wget is failing to give me the expected output. </p>
  
  <p>The code: </p>
  
  <pre><code>#!/bin/bash
  load_page()
  {
      echo "url=$url";
      echo "headers=$header_str";
      /usr/bin/time -f "\t%e\t%C" wget -kKHpq --no-cache "$header_str" "$url" 
  }
  read_config_file()
  {
      while read cfg_line
      do
          if [[ ! "$cfg_line" = \#* ]] &amp;&amp; [[ "x$cfg_line" != "x" ]] ; then    
              url=`echo $cfg_line | cut -d";" -f1`
              fields=`echo $cfg_line | awk -F";" ' { print NF } ' `; 
              f_cnt=2;
              unset header_str
              while [ $f_cnt -le $fields ] ; 
              do
                  field=`echo $cfg_line | cut -d";" -f$f_cnt`;
                  header_name=`echo $field | cut -d":" -f1`;
                  header_val=`echo $field | cut -d":" -f2`;
                  header_str="${header_str}--header=\"${header_name}: $header_val\" "
                  f_cnt=`expr $f_cnt + 1`;
              done
              load_page 
          fi
      done&lt;urls.cfg   
  }
  main()
  {
      read_config_file
  }
  main $@
  </code></pre>
  
  <p>The output: </p>
  
  <pre><code>url=http://some-website.com/
  
  headers=--header="User-Agent: XYZ G" --header="msisdn: 98xxxxxxxx" 
  
  6.37    wget -kKHpq --no-cache --header="User-Agent: XYZ G" --header="msisdn: 98xxxxxxxx"  http://some-website.com/
  </code></pre>
  
  <p>Every thing looks fine however no proper page is fetched. If I copy paste the command from output then server responds with expected page. </p>
  
  <p>when ran shell script in debug mode ; I think this is the problem. The headers string is getting wrapped into the single quotes in wget command.</p>
  
  <p>please help. </p>
  
  <pre><code>+ load_page
  + echo url=http://some-website.com/
  url=http://some-website.com/
  + echo 'headers=--header="User-Agent: XYZ G" --header="msisdn: 98xxxxxxxx" '
  headers=--header="User-Agent: XYZ G" --header="msisdn: 98xxxxxxxx" 
  + /usr/bin/time -f '\t%e\t%C' wget -kKHpq --no-cache '--header="User-Agent: XYZ G" --header="msisdn: 98xxxxxxxx" ' http://some-website.com/
      1.66    wget -kKHpq --no-cache --header="User-Agent: XYZ G" --header="msisdn: 98xxxxxxxx"  http://some-website.com/
  </code></pre>