bash: Conditional expressions < and > do not perform as documented.

Bug #349658 reported by William Shotts
6
Affects Status Importance Assigned to Milestone
Gnu Bash
Confirmed
Undecided
Unassigned
bash (Ubuntu)
Triaged
Medium
Unassigned

Bug Description

Binary package hint: bash

In the bash documentation, the conditional expression string1 > string2 is said to be true if string1 sorts after string2 lexicographically according to the current locale. However (example from 8.04):

bshotts@twin2:~$ lsb_release -rd
Description: Ubuntu 8.04.2
Release: 8.04

bshotts@twin2:~$ apt-cache policy bash
bash:
  Installed: 3.2-0ubuntu18
  Candidate: 3.2-0ubuntu18
  Version table:
 *** 3.2-0ubuntu18 0
        500 http://us.archive.ubuntu.com hardy-updates/main Packages
        100 /var/lib/dpkg/status
     3.2-0ubuntu16 0
        500 http://us.archive.ubuntu.com hardy/main Packages

bshotts@twin2:~$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

bshotts@twin2:~$ [ 'b' \> 'a' ] && echo true # works
true
bshotts@twin2:~$ [ 'b' \> 'A' ] && echo true # works
true
bshotts@twin2:~$ [ 'B' \> 'a' ] && echo true # does not work, should be true
bshotts@twin2:~$ [ 'B' \> 'A' ] && echo true #works
true
bshotts@twin2:~$ [ 'Z' \> 'a' ] && echo true # does not work, should be true
bshotts@twin2:~$

The results of the third and fifth cases ( 'B' \> 'a' and 'Z' \> 'a' ) suggest that POSIX collation order is being used rather than the collation order for the current locale.

Revision history for this message
Colin Watson (cjwatson) wrote :

Indeed - the implementation uses strcmp() rather than strcoll().

Changed in bash (Ubuntu):
importance: Undecided → Medium
status: New → Triaged
Revision history for this message
Colin Watson (cjwatson) wrote :

This was sent upstream recently, and acknowledged as a bug (possibly documentation, possibly code):

  http://lists.gnu.org/archive/html/bug-bash/2009-04/msg00055.html

Changed in gnubash:
status: New → Confirmed
Revision history for this message
Ralph Corderoy (ralph-inputplus) wrote :

10.10's bash 4.1-2ubuntu4's bash(1) now says < and > compare lexicographically in the current locale if used with [[...]] else just that they compare lexicographically (with no mention of locale).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.