I am trying to find if two ip addresses are the same or not. I admit that I am new with bash, but I see no reason this would not work:
if [[ "$IPAddress" != "$OLDIPAddress" ]]
then
echo "IP Not the Same"
else
echo "IP Same"
fi
For testing purposes, I have even hard coded the values for the two variables, and they still don't show up as the same. I know you don't always see your own typos, but I do not see why this would not work. Any ideas?
Quick demo script for comparing differently formated ip addresses, "normal" vs. DHCP always 3 digit octets for instance. Hopefully a couple of useful tricks you can use for parsing and validation in addition to compares, and a catalyst for some more from the community. (This is my first post with code so hopefully it comes through ok - as always YMMV.)
While your command should work, you can use the simple test operator (just a single bracket). The advantage is that it will work with any (POSIX) shell. However, the
[[
operator should work too.Can you reproduce this little example? (Should output 'yes'):