Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    5

    Unanswered: 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.

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    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.

  3. #3
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    The following commands whill give you the Minimum and Maximum value for an integer :
    Code:
    getconf INT_MIN
    getconf INT_MAX
    Jean-Pierre.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •