Shell判断输入是否有效IP和字母
1个回答
展开全部
#! /bin/bash
function checkip {
for var in `echo $1 | awk -F. '{print $1, $2, $3, $4}'`
do
if [ $var -ge 1 -a $var -le 255 ]
then
continue
else
return 1
fi
done
}
echo -n 'Give me a IP address to check:'
read ip
checkip $ip
case $? in
0)
echo "Your input $ip is a valid IP address.";;
1)
echo "Your input $ip is invalid.";;
esac
function checkip {
for var in `echo $1 | awk -F. '{print $1, $2, $3, $4}'`
do
if [ $var -ge 1 -a $var -le 255 ]
then
continue
else
return 1
fi
done
}
echo -n 'Give me a IP address to check:'
read ip
checkip $ip
case $? in
0)
echo "Your input $ip is a valid IP address.";;
1)
echo "Your input $ip is invalid.";;
esac
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询