![Bash:-:-通过while和shift判断脚本位置参数格式是否合法 Bash:-:-通过while和shift判断脚本位置参数格式是否合法](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
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