Você pode fazer todas essas transformações no bash, com :
pingd() (
domain=$1
# allow 'http' or 'www' to match any upper- or lower-case versions
# (bash version 4.4-alpha and later)
shopt -s nocasematch
# strip any leading http(s)
domain=${domain/#http:\/\/}
domain=${domain/#https:\/\/}
# strip any leading user:pass@
domain=${domain/#*:*@/}
# strip the trailing slash onwards
domain=${domain/%\/*/}
# strip any trailing port
domain=${domain/%:*/}
# strip any remaining leading www
domain=${domain/#www./}
ping "$domain"
)
Exemplos (com echo ping
em vez de apenas ping
, para demonstrar):
$ pingd 'http://user:[email protected]:80/some/path/url?data&and#hash'
ping example.com
$ pingd 'http://www.stackexchange.com'
ping stackexchange.com
$ pingd 'http://www.stackexchange.com/help'
ping stackexchange.com
$ pingd 'https://www.stackexchange.com'
ping stackexchange.com
$ pingd 'https://unix.stackexchange.com'
ping unix.stackexchange.com
$ pingd 'https://unix.stackexchange.com/'
ping unix.stackexchange.com
$ pingd 'https://unix.stackexchange.com/questions/428989/allow-full-urls-starting-with-http-https-or-www-in-ping'
ping unix.stackexchange.com
$ pingd 'www.example.com'
ping example.com