Bug 136688 - bash -gt logic broken comparing large integers
Summary: bash -gt logic broken comparing large integers
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux 2.1
Classification: Red Hat
Component: bash
Version: 2.1
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Pete Graner
QA Contact: Ben Levenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-10-21 17:59 UTC by Richard Leyton
Modified: 2007-11-30 22:06 UTC (History)
0 users

Fixed In Version: 2.05b-29.0.3
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2007-08-29 18:52:09 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Reproduction of gt bug (172 bytes, text/plain)
2004-10-21 18:32 UTC, Richard Leyton
no flags Details
Reproduction of gt bug (174 bytes, text/plain)
2004-10-21 18:35 UTC, Richard Leyton
no flags Details

Description Richard Leyton 2004-10-21 17:59:34 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3)
Gecko/20040913 Firefox/0.10

Description of problem:
bash incorrectly returns a false boolean value when comparing two long
integers (YYYYMMDDHHMMSS), specifically:

if [ 20041021183908 -gt 20041021183406 ]

returns false when it should return true

Version-Release number of selected component (if applicable):
bash-2.05-8.2

How reproducible:
Always

Steps to Reproduce:
Create a script:

#!/bin/bash
v1=20041021183908
v2=20041021183406

if [ $v1 -gt $v2 ]
then
  echo "$v1 is greater than $v2"
else
  echo "$v1 is less than $v2"
fi

Run it!

Actual Results:  Output of script reads

20041021183908 is less than 20041021183406

Which is incorrect.



Expected Results:  It should read:

20041021183908 is greater than 20041021183406

Additional info:

Works fine on RHE3 (bash-2.05b-29.0.3)

Comment 1 Richard Leyton 2004-10-21 18:25:02 UTC
The obvious work-around is to use the ">" operator, which we're doing
right now.

Comment 2 Richard Leyton 2004-10-21 18:32:25 UTC
Created attachment 105601 [details]
Reproduction of gt bug

Comment 3 Richard Leyton 2004-10-21 18:35:18 UTC
Created attachment 105602 [details]
Reproduction of gt bug

Reproduction script

Comment 4 Pete Graner 2007-08-29 18:52:09 UTC
Fixed in newer versions of bash. Closing.


Note You need to log in before you can comment on or make changes to this bug.