bash shell if 正则
参考博客:https://blog.csdn.net/haobashenmegui/article/details/103630550
参考博客:https://www.cnblogs.com/gaochsh/p/6901807.html
在[[…]]里面不要双引号
#!/usr/bin/bash
s="hello"
s2="good"
if [[ ${s} =~ (^he*)|(^go*) ]];then
echo "success!"
else
echo "failed!"
fi
if [[ ${s2} =~ (^he*)|(^go*) ]];then
echo "success!"
else
echo "failed!"
fi
newip='192.168.1.100'
reg='^([0-9]{1,3}.){3}[0-9]{1,3}$'
if [[ "$newip" =~ $reg ]];then
echo '找到了ip地址'
fi