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
Using only bash builtins:
path="/${url#*://*/}" && [[ "/${url}" == "${path}" ]] && path="/"
What this does is:
*://*/
(so this would be your protocol and hostname+port)/
note: the quotation marks aren't actually needed here, but I find it easier to read with them in