Bourne shell if statemenet question
I am trying to compare to IP addresses, but the ifstatement is bombing on the "." in the ip address. Do you know anyway I can get the ifstatement to not mess up on the "."'s in the ip address. Thanks for they help.
IPA="192.158.0.100" IPB="192.168.78.2" if [ "$IPA" -eq "$IPB" ]; then |
"-eq" tries to compare them as numbers. So it will accept only one "." at best.
If you compare them as strings, using a "=" (or "==" (a bash thing I believe)) instead of "-eq" it will work. |
Yes it's logical! To compare strings use the = not the string equivalent (-eq), and to compare numbers use -eq, which is the string equivalent of the =. :scratch:
Excuse me but; 1 = 1 "one" -eq "one" Seems more logical. :confused: |
Yes but -eq is part of a family of operators
-lt, -gt, -ne, -le, -ge which all take integers as their operands, whereas there is only one string comparison operator "=". man test for all the gory details. |
All times are GMT -5. The time now is 10:53 AM. |