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
In bash:
URL='http://login:password@example.com/one/more/dir/file.exe?a=sth&b=sth' URL_NOPRO=${URL:7} URL_REL=${URL_NOPRO#*/} echo "/${URL_REL%%\?*}"
Works only if URL starts with http:// or a protocol with the same length Otherwise, it's probably easier to use regex with sed, grep or cut ...
http://
sed
grep
cut