在shell中使用正则表达式,判断域名
正则表达式匹配域名
^(http(s)?:\/\/)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:[0-9]{1,5})?$
在shell中使用
read -p "请输入域名: " input_domain
echo "域名为: $input_domain"
flag=$(echo $input_domain | gawk '/^(http(s)?:\/\/)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:[0-9]{1,5})?$/{print $0}')
if [ ! -n "${flag}" ]; then
echo "请输入正确的域名"
fi
循环
domain_flag=''
until [ "$domain_flag" != '' ]
do
read -p "请输入域名: " input_domain
echo "域名为: $input_domain"
domain_flag=$(echo $input_domain | gawk '/^(http(s)?:\/\/)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:[0-9]{1,5})?$/{print $0}')
if [ ! -n "${domain_flag}" ]; then
echo "域名有误,请重新输入!!!"
fi
done