Bug 189766

Summary: Bug in case statement using pattern matching in function
Product: [Fedora] Fedora Reporter: Austin France <austin.france>
Component: bashAssignee: Tim Waugh <twaugh>
Status: CLOSED NOTABUG QA Contact: Ben Levenson <benl>
Severity: medium Docs Contact:
Priority: medium    
Version: 4   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-04-24 15:11:24 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Test Script none

Description Austin France 2006-04-24 14:36:31 UTC
Description of problem:

Bash behaving unexpecadly in a case statement.  The following test script 
demonstrates:

is_syslib()
{
        case $1 in
        L[a-z]*) echo "[$1] Begins with L then lower case" ; return 2 ;;
        [A-Z]*)  echo "[$1] Begins with uppercase letter" ; return 0 ;;
        *)       echo "[$1] is probably lowercase" ; return 1 ;;
        esac
}

is_syslib DEF
is_syslib ad
is_syslib in
is_syslib mx
is_syslib sq

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

[root@spindhella ~]# bash --version
GNU bash, version 3.00.16(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.

How reproducible:

100% reproducable.

Steps to Reproduce:
1. Place the example code above into /tmp/test_bash_bug
2. bash /tmp/test_bash_bug
  
Actual results:

[root@spindhella ~]# bash /tmp/tstit
[DEF] Begins with uppercase letter
[ad] is probably lowercase
[in] Begins with uppercase letter
[mx] Begins with uppercase letter
[sq] Begins with uppercase letter

Expected results:

[root@spindhella ~]# ksh /tmp/tstit    # Korn shell does not exhibit this bug
[DEF] Begins with uppercase letter
[ad] is probably lowercase
[in] is probably lowercase
[mx] is probably lowercase
[sq] is probably lowercase

Additional info:

The bug also appears in 2.05a.0 version of bash on RH 7.3

  # bash --version
  GNU bash, version 2.05a.0(1)-release (i686-pc-linux-gnu)
  Copyright 2001 Free Software Foundation, Inc.

Both the AT&T ksh (sh (AT&T Labs Research) 1993-12-28 q) and pdksh produce the 
expected output.

On HPUX 10.20: sh, ksh and bash v 2.04.0 produce the expected output.

Comment 1 Austin France 2006-04-24 14:36:31 UTC
Created attachment 128149 [details]
Test Script

Comment 2 Tim Waugh 2006-04-24 15:11:24 UTC
[A-Z] only means 'upper case letters' in the C locale.  In all other locales, it
means A through to Z (as you would see list in dictionary or a book's index).

The glob for 'any upper case letter' is '[[:upper:]]'.  See the 'Pattern
Matching' section of 'Pathname Expansion' in the bash man page.