title: How to grep curl -I header information
body: <p>I'm trying to get the redirect link from a site by using <code>curl -I</code> then <code>grep</code> to "location" and then <code>sed</code> out the location text so that I am left with the URL. </p>
  
  <p>But this doesn't work. It outputs the URL to screen and doesn't put it</p>
  
  <pre><code>test=$(curl -I "http://www.redirectURL.com/" 2&gt; /dev/null | grep "location" | sed -E 's/location:[ ]+//g')
  echo "1..$test..2"
  </code></pre>
  
  <p>Which then outputs:</p>
  
  <pre><code>..2http://www.newURLfromRedirect.com/bla
  </code></pre>
  
  <p>What's going on?</p>