I have a function I wanted to use for getting/checking website certs. I use ZSH but wanted to test it in BASH as well to verify that it works as well in that shell.
The function seems to print out the content as a single line and isn't noticing or keeping the newlines from the openssl command. ZSH handles it just fine and works as expected.
What can I do to get bash to notice the new lines when the openssl command returns?
function get-cert() {
if (( $# == 2 )); then
site_url=${1}
site_port=${2}
elif (( $# == 1 )); then
site_url=${1}
site_port=443
else
echo -n "Enter site domain to get and view the cert: "
read site_url
echo -n "Enter the port [443]: "
read site_port
site_port=${site_port:-443}
fi
echo " === Getting cert for site ${site_url}:${site_port}"
content="$(openssl s_client -showcerts -servername ${site_url} -connect ${site_url}:${site_port} </dev/null)"
if [[ $? == "0" ]]; then
echo ${content}
else
echo "Failed to get cert for ${site_url}"
fi
}