Bash:-:-通过while和shift判断脚本位置参数格式是否合法

时间:2023-03-09 13:25:43
Bash:-:-通过while和shift判断脚本位置参数格式是否合法
if [[ $# -lt  ]];then
echo "请输入2个位置参数..."
exit
else
num=$#
while(($#>=));do case ${num} in
)
if ! echo "${1}" | grep -qP "\d+\.\d+\.\d+\.\d+";then
echo "中心机IP输入格式不对..."
exit
fi SALT_MASTER_IP=${}
;;
) if ! echo "${1}" | grep -qP "AAAA_\w+_(ENGINE|COMMON|WEB)_\d+\.\d+\.\d+\.\d+";then
echo "salt-minion主机名不对..."
exit
fi SALT_MINION_LOCAL=${}
;;
*)
echo "输入超过2个位置参数无效..."
echo "salt-minion.sh 中心机IP 本地主机名"
exit
;;
esac num=`expr ${num} - `
shift
done
fi