compare two IP address using bc
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am trying to compare two IP address using bc command however the IP with lower numeric value is not being trapped in the test.
Here is my code:
TEST=$(echo "$i < $IP_BRD && $i > $IP_LOW " | bc -q )
If TEST
results to 1, the process continues else exits.
check the below example:
++ echo '191.35 < 187.254 && 191.35 > 184.1 '
+ TEST=0
++ echo '191.35 < 191.254 && 191.35 > 188.1 '
++ bc -q
+ TEST2=0
++ echo '191.35 < 195.254 && 191.35 > 192.1 '
++ bc -q
+ TEST3=0
+ [[ 0 = 1 ]]
+ [[ 0 = 1 ]]
+ [[ 0 = 1 ]]
In line echo '191.35 < 191.254 && 191.35 > 188.1 '
the IP 191.35 is less than 191.254 however its not being seen as it.
I have tried double quoutes in the TEST=$(echo "$i < $IP_BRD && $i > $IP_LOW " | bc -q )
however didnt had much success.
Any ideas how to fix it ?
shell-script scripting
add a comment |Â
up vote
0
down vote
favorite
I am trying to compare two IP address using bc command however the IP with lower numeric value is not being trapped in the test.
Here is my code:
TEST=$(echo "$i < $IP_BRD && $i > $IP_LOW " | bc -q )
If TEST
results to 1, the process continues else exits.
check the below example:
++ echo '191.35 < 187.254 && 191.35 > 184.1 '
+ TEST=0
++ echo '191.35 < 191.254 && 191.35 > 188.1 '
++ bc -q
+ TEST2=0
++ echo '191.35 < 195.254 && 191.35 > 192.1 '
++ bc -q
+ TEST3=0
+ [[ 0 = 1 ]]
+ [[ 0 = 1 ]]
+ [[ 0 = 1 ]]
In line echo '191.35 < 191.254 && 191.35 > 188.1 '
the IP 191.35 is less than 191.254 however its not being seen as it.
I have tried double quoutes in the TEST=$(echo "$i < $IP_BRD && $i > $IP_LOW " | bc -q )
however didnt had much success.
Any ideas how to fix it ?
shell-script scripting
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to compare two IP address using bc command however the IP with lower numeric value is not being trapped in the test.
Here is my code:
TEST=$(echo "$i < $IP_BRD && $i > $IP_LOW " | bc -q )
If TEST
results to 1, the process continues else exits.
check the below example:
++ echo '191.35 < 187.254 && 191.35 > 184.1 '
+ TEST=0
++ echo '191.35 < 191.254 && 191.35 > 188.1 '
++ bc -q
+ TEST2=0
++ echo '191.35 < 195.254 && 191.35 > 192.1 '
++ bc -q
+ TEST3=0
+ [[ 0 = 1 ]]
+ [[ 0 = 1 ]]
+ [[ 0 = 1 ]]
In line echo '191.35 < 191.254 && 191.35 > 188.1 '
the IP 191.35 is less than 191.254 however its not being seen as it.
I have tried double quoutes in the TEST=$(echo "$i < $IP_BRD && $i > $IP_LOW " | bc -q )
however didnt had much success.
Any ideas how to fix it ?
shell-script scripting
I am trying to compare two IP address using bc command however the IP with lower numeric value is not being trapped in the test.
Here is my code:
TEST=$(echo "$i < $IP_BRD && $i > $IP_LOW " | bc -q )
If TEST
results to 1, the process continues else exits.
check the below example:
++ echo '191.35 < 187.254 && 191.35 > 184.1 '
+ TEST=0
++ echo '191.35 < 191.254 && 191.35 > 188.1 '
++ bc -q
+ TEST2=0
++ echo '191.35 < 195.254 && 191.35 > 192.1 '
++ bc -q
+ TEST3=0
+ [[ 0 = 1 ]]
+ [[ 0 = 1 ]]
+ [[ 0 = 1 ]]
In line echo '191.35 < 191.254 && 191.35 > 188.1 '
the IP 191.35 is less than 191.254 however its not being seen as it.
I have tried double quoutes in the TEST=$(echo "$i < $IP_BRD && $i > $IP_LOW " | bc -q )
however didnt had much success.
Any ideas how to fix it ?
shell-script scripting
shell-script scripting
asked 2 hours ago
Atul
3322517
3322517
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
In line echo '191.35 < 191.254 && 191.35 > 188.1 ' the IP 191.35 is less than 191.254 however its not being seen as it.
No, it's not: 191.35 == 191.350 > 191.254. bc compares them numerically, it can't compare IPs directly. You should convert the IP to integer first. Then you can compare them using shell built-ins without resorting to external tools.
Edit: check out this thread: IP Address Converter
New contributor
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
In line echo '191.35 < 191.254 && 191.35 > 188.1 ' the IP 191.35 is less than 191.254 however its not being seen as it.
No, it's not: 191.35 == 191.350 > 191.254. bc compares them numerically, it can't compare IPs directly. You should convert the IP to integer first. Then you can compare them using shell built-ins without resorting to external tools.
Edit: check out this thread: IP Address Converter
New contributor
add a comment |Â
up vote
0
down vote
In line echo '191.35 < 191.254 && 191.35 > 188.1 ' the IP 191.35 is less than 191.254 however its not being seen as it.
No, it's not: 191.35 == 191.350 > 191.254. bc compares them numerically, it can't compare IPs directly. You should convert the IP to integer first. Then you can compare them using shell built-ins without resorting to external tools.
Edit: check out this thread: IP Address Converter
New contributor
add a comment |Â
up vote
0
down vote
up vote
0
down vote
In line echo '191.35 < 191.254 && 191.35 > 188.1 ' the IP 191.35 is less than 191.254 however its not being seen as it.
No, it's not: 191.35 == 191.350 > 191.254. bc compares them numerically, it can't compare IPs directly. You should convert the IP to integer first. Then you can compare them using shell built-ins without resorting to external tools.
Edit: check out this thread: IP Address Converter
New contributor
In line echo '191.35 < 191.254 && 191.35 > 188.1 ' the IP 191.35 is less than 191.254 however its not being seen as it.
No, it's not: 191.35 == 191.350 > 191.254. bc compares them numerically, it can't compare IPs directly. You should convert the IP to integer first. Then you can compare them using shell built-ins without resorting to external tools.
Edit: check out this thread: IP Address Converter
New contributor
edited 1 hour ago
New contributor
answered 1 hour ago
divlamir
11
11
New contributor
New contributor
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474395%2fcompare-two-ip-address-using-bc%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password