- 论坛徽章:
- 0
|
#!/bin/bash
while :;do
read -p "Please Input Your IP [192.168.1.0 ||quit]: " IP
#if [[ "$IP" =~ ^192\.168\.1\.\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>$ ]];then
if [[ "$IP" =~ ^192\.168\.1\.([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]];then
cat >> /tmp/1.txt <<EOF
IPADDR="$IP"
PREFIX="24"
GATEWAY="192.168.1.254"
DNS1="192.168.1.1"
EOF
else
echo failed
fi
done
如果我输入的IP为:192.168.1.23。上面的两个if语句,加了注释的无法执行,会只执行到echo failed的分支上。按照精确匹配来讲,是要使用\< \>但是总是匹配不到。后来查了man bash中有这么一句:When used with [[, The < and > operators sort lexicographically using the current locale。不知道该怎么理解,请各位大神不吝赐教!
|
|