Thanks, that helped me. I made some improvements and wrapped that in a helper script "finalurl":
#!/bin/bash
curl $1 -s -L -I -o /dev/null -w '%{url_effective}'
-o
output to /dev/null
-I
don't actually download, just discover the final URL-s
silent mode, no progressbarsThis made it possible to call the command from other scripts like this:
echo `finalurl http://someurl/`