I am trying to validate an ip address within a dash script. I've found many ways to achieve the same with bash such as in linuxjournal
Basically what is does is a comparision using this:
if [[ $ip =~ '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' ]]; then
do something
fi
Is there any way to get the same with dash?
UPDATE: This is the final script that does what I needed:
#In case RANGE is a network range (cidr notation) it's splitted to every ip from
# that range, otherwise we just keep the ip
if echo $RANGE | grep -E -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}$'; then
IPS=`prips $RANGE -e ...0,255`
if [ "$?" != "0" ] ; then
echo "ERROR: Not a valid network range!"
exit 1
fi
elif echo $RANGE | grep -E -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'; then
IPS="$RANGE"
else
echo "$RANGE no is not a valid IP address or network range"
exit 1
fi