About Pinging URLs instead of Domains

The ping command accepts only the domain name, so if you copy a URL from a browser, you always need to manually delete the protocol there.

As a workaround, you can create a wrapper function in ~/.zshrc or ~/.bashrc that accepts any URL or domain:

pingurl() {
    ping "$(echo "$1" | sed -E 's#^(https?://)?([^/]+).*#\2#')"
}

Use it as follows:

$ pingurl https://example.com

Tips and Tricks Programming Dev Ops Bash Zsh