Assuming your shell is bash
, you should probably use arrays:
givenip=172.27.18.191
ip1=( $(sed 's/\./ /g' <<< 172.27.16.123) )
ip2=( $(sed 's/\./ /g' <<< 172.27.19.254) )
ip3=( $(sed 's/\./ /g' <<< $givenip) )
Then you can compare components:
givenip=172.27.18.191
ip1=( $(sed 's/\./ /g' <<< 172.27.16.123) )
ip2=( $(sed 's/\./ /g' <<< 172.27.19.254) )
ip3=( $(sed 's/\./ /g' <<< $givenip) )
if [ "${ip3[0]}" -ge "${ip1[0]}" -a "${ip3[0]}" -le "${ip2[0]}" ] &&
[ "${ip3[1]}" -ge "${ip1[1]}" -a "${ip3[1]}" -le "${ip2[1]}" ] &&
[ "${ip3[2]}" -ge "${ip1[2]}" -a "${ip3[2]}" -le "${ip2[2]}" ] &&
[ "${ip3[3]}" -ge "${ip1[3]}" -a "${ip3[3]}" -le "${ip2[3]}" ]
then echo $givenip is between two established IP addresses
else echo $givenip is not between the two established IP addresses
fi