mainThe GNU Bourne-Again SHell - Support: sr #108609, In en-US.UTF-8 locale, '*[A-Z]*'...

 
 

sr #108609: In en-US.UTF-8 locale, '*[A-Z]*' matches very oddly

Submitter:  None
Submitted:  Thu 03 Jul 2014 02:42:38 AM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Invalid
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 25 Mar 2015 10:46:24 AM UTC, comment #2: 

Not a bug.

That's just how character sets work. If you want the set of upper case characters, use [:upper:].

The locale specifies the ordering, so I guess under this locale, [A-Z] means: [AbBcCdD..zZ], that's why it doesn't match 'a'.

The only locale guaranteed to have that ordering for ranges ([a-z], [A-Z], ...) is the POSIX locale (LANG=C or LANG=POSIX)

Eduardo Bustamante <dualbus>
Thu 03 Jul 2014 03:13:56 AM UTC, comment #1: 

My attempt to use markup formatting appears to have caused the web interface to not display the text, so here is the plain version (minus the first line, which did come through). My apologies if this is redundant.

The demonstration:

$ cat Demo
# shell script
for i in "$@"; do
  case "$i" in
    [A-Z]) echo "$i has upper case";;
  esac
done
$ env - LANG=en_US.UTF-8 ./bash ./Demo a b C y z
b has upper case
C has upper case
y has upper case
z has upper case
$

This was tested with a fresh-compiled build from the latest git tip on 64-bit Ubuntu 14.04. I can (re)produce this behavior in at least Bash 4.3.11 (Ubuntu 14.04), 4.2.47 (Fedora 20), and 4.2.25 (Ubuntu 12.04).

Assuming that it is desirable for '*[A-Z]*' to match lower case characters at all in this context (I believe that it is a mistake to do so and it certainly doesn't match the behavior of other POSIX-compatible shells), bash should at least match 'a' too.

A mirror image of this bug happens if you use '*[a-z]*' and test against upper case letters; 'Z' does not match although A-Y do.

Chris Siebenmann <cks>
Thu 03 Jul 2014 02:42:38 AM UTC, original submission:  

It's easiest to show this as a demonstration:


$ cat Demo
# shell script
for i in "$@"; do
  case "$i" in
    *[A-Z]*) echo "$i has upper case";;
  esac
done
$ env - LANG=en_US.UTF-8 ./bash ./Demo a b C y z
b has upper case
C has upper case
y has upper case
z has upper case
$
+verbatim+

This has been reproduced with a build from the latest git tip.

Assuming that it is desirable for '*[A-Z]*' to match lower case characters at all in this context (I believe that it is a mistake to do so), bash should at least match 'a' too. There is a symmetrical issue if you match '*[a-z]*' where 'Z' does not match although A-Y do.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Updated the item)
  • -email is unavailable- added by dualbus (Posted a comment)
  • -email is unavailable- added by dennisne
  • -email is unavailable- added by cks (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-11-13 chet StatusNone Invalid
    2014-07-04 dennisne Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.14-8eb0.
    Corresponding source code