echo "${URL}" | awk -F/ '{print $3}' | sed 's/:.*//'
さまざまな可能性をテストする要点は次のとおりです。
サンプルラン:
# ./get_domain_from_url.sh
For URL:http://1.1.1.1, domain name:1.1.1.1
For URL:http://1.1.1.1:8443, domain name:1.1.1.1
For URL:https://1.1.1.1, domain name:1.1.1.1
For URL:https://1.1.1.1:8443, domain name:1.1.1.1
For URL:http://hello-world, domain name:hello-world
For URL:http://hello-world.com, domain name:hello-world.com
For URL:http://sub.hello-world.com, domain name:sub.hello-world.com
For URL:http://hello-world:8080, domain name:hello-world
For URL:http://hello-world.com:8080, domain name:hello-world.com
For URL:http://sub.hello-world.com:8080, domain name:sub.hello-world.com
For URL:https://hello-word/foo/bar, domain name:hello-word