LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bourne shell if statemenet question (https://www.linuxquestions.org/questions/programming-9/bourne-shell-if-statemenet-question-80727/)

Mike_the_Man 08-10-2003 04:50 PM

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

Hko 08-10-2003 06:44 PM

"-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.

/bin/bash 08-11-2003 11:16 AM

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:

Corin 08-11-2003 02:18 PM

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.