Q:

cURL redirect vs. manual redirect discrepancy

Using the following code to log the final redirected URL - 
REDIRECT=`curl -w "%{redirect_url}" --user-agent "Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1 (KHTML, Like Gecko) Version/6.0.0.141 Mobile Safari/534.1" -o /dev/null -silent http://madmoney.cnbc.com`
if !([[ $REDIRECT ]])
then
    echo $URL
else
    echo ${REDIRECT}
fi

The output of this script is 
http://www.cnbc.com/id/15838459

When I manually visit the URL http://madmoney.cnbc.com in the Firefox browser using the exact same user-agent (as in the script) I get this URL
http://m.cnbc.com//id/15838459

which is the expected output. What am I doing wrong?

A:

$ curl -Ls -A BlackBerry -o /dev/null -w %{url_effective} madmoney.cnbc.com
http://m.cnbc.com//id/15838459

