john john - 3 months ago 8
Bash Question

Using Bash to determine if URL is HTTP or HTTPS

Is there a way In bash to determine if a URL uses SSL? Before I send anything else to the URL I want to find out if it only accepts HTTP or HTTPS connections.

Answer

You can use the below script if you have access to wget.

#/bin/bash    
URL=google.com
if wget --spider https://$URL 2>/dev/null; then
  echo "https is present"
else
  echo "https not present"
fi

Please note that you need to have http_proxy / https_proxy set.

I tested the above script in cygwin64 [dont have access to nix system as of now]

You should be also able to modify the same script using curl.