If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Limitation of numeric test using "if"

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-05-04, 00:31
wrcastro_ph wrcastro_ph is offline
Registered User
 
Join Date: Oct 2003
Posts: 5
Limitation of numeric test using "if"

Hi, I'm creating a script in KSH and if I use this command it gives an output that's crazy. Actually, I doing a test on the account number ranges.

if [ 10402000000002 -le 10103000000001 ];then
echo " LESS THAN OR EQUAL"
else
echo " GREATER THAN"
fi

RESULT : LESS THAN or EQUAL


But the RESULT should be GREATER THAN.


I did another test and if I lesser the numbers ... say up to 10 digits only, it goes well.

Question :

1. Is there a limition in the number of digits in this "if" command?
2. How test this large value?

Thanks for your advise.
Reply With Quote
  #2 (permalink)  
Old 04-06-04, 03:31
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
I have no problem on my AIX system with your values, but the problem appears with greater values.
Try to use bc to make your test, you can do something like this :
Code:
function LessOrEqual {
   [ -n "$(echo "if ($1 <= $2) 1" | bc)" ]
}

if LessOrEqual 104020000000000000 101030000000010000 
   then echo "LESS THAN OR EQUAL"
   else echo "GREATER THAN "
fi
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 04-09-04, 04:19
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
The following commands whill give you the Minimum and Maximum value for an integer :
Code:
getconf INT_MIN
getconf INT_MAX
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On