我有一个我想用来获取/检查网站证书的功能。我使用ZSH但是想在BASH中测试它以验证它在那个shell中是否也能正常工作。
该函数似乎将内容打印为单行,并且没有注意到或保留openssl命令中的换行符。 ZSH处理得很好并按预期工作。
当openssl命令返回时,我该怎么做才能让bash注意到新行?
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
}
答案 0 :(得分:1)
echo ${content}
此行将内容分解为单词,并将每个单词作为参数传递给echo,后者用空格分隔它们。用引号括起来。
echo "${content}"