#!/bin/bash
read -p "请输入ip地址:" ip
echo $ip
echo "$ip" | grep -E --color '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])\.(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){2}([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])$'
if [ $? -ne 0 ];then
echo "你输入ip地址不符和要求"
fi
转载于:https://blog.51cto.com/baixueping/1554952