Created
October 17, 2020 12:54
-
-
Save dhsathiya/08e8ddb3b6e6c4d6cb79595323138f94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# extract the protocol | |
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')" | |
# remove the protocol | |
url="$(echo ${1/$proto/})" | |
# extract the user (if any) | |
user="$(echo $url | grep @ | cut -d@ -f1)" | |
# extract the host and port | |
hostport="$(echo ${url/$user@/} | cut -d/ -f1)" | |
# by request host without port | |
host="$(echo $hostport | sed -e 's,:.*,,g')" | |
# by request - try to extract the port | |
port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')" | |
# extract the path (if any) | |
path="$(echo $url | grep / | cut -d/ -f2-)" | |
echo "url: $url" | |
echo " proto: $proto" | |
echo " user: $user" | |
echo " host: $host" | |
echo " port: $port" | |
echo " path: $path" | |
# From Stackoverflow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment