In my bash script I need to extract just the path from the given URL. For example, from the variable containing string:
http://login:password@example.com/one/more/dir/fi
This perl one-liner works for me on the command line, so could be added to your script.
echo 'http://login:password@example.com/one/more/dir/file.exe?a=sth&b=sth' | perl -n -e 'm{http://[^/]+(/[^?]+)};print $1'
Note that this assumes there will always be a '?' character at the end of the string you want to extract.