bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug in string pattern matching


From: skt
Subject: bug in string pattern matching
Date: Tue, 18 May 2004 20:11:40 -0700

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: i386-redhat-linux-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib 
-D_GNU_SOURCE  -O2 -march=i386 -mcpu=i686 -g
uname output: Linux skywalker.ca.boeing.com 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 
2003 i686 i686 i386 GNU/Linux
Machine Type: i386-redhat-linux-gnu

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:
        [Detailed description of the problem, suggestion, or complaint.]
There is a bug in how string pattern matching works.

Repeat-By:
        [Describe the sequence of events that causes the problem
        to occur.]
Run this script:
#!/bin/sh
# 5/18/04 - S.K.Tazuma
#
# Code below demonstrates a bug in bash
# when run on RedHat Linux 8.0/9.0
# which uses bash version 2.05b(0).
# Also happens with 2.05a and 2.05.
#
# It does not happen on 2.03 or 2.04.21 versions of bash.
# Nor does it happen on 2.05b.0(8) cygwin version of bash (running
#       on Windows of course).  Since the version is the same as the one
#       that shows the bug on Linux, this might imply a library problem.
#       But since it doesn't occur when running the 2.04.21 version of bash
#       on RedHat 9.0, that would suggest the problem is in the bash
#       source code.

echo "BASH_VERSION = $BASH_VERSION"
echo ''

list='aaa bbb zzz AAA BBB ZZZ'

for str in $list
do
    if [[ $str == [A-Z]* ]]
    then
        echo yes on str = $str
    else
        echo no on str = $str
    fi
done

echo ''

for str in $list
do
    case $str in
    [A-Z]*)
        echo yes on str = $str
        ;;
    *)
        echo no on str = $str
        ;;
    esac
done

echo ''
echo 'the correct result for the above'
echo 'should be a "no" on each lower-case string,'
echo 'and a "yes" on each upper-case string'
echo ''

echo 'the correct result for the below'
echo 'should be a "yes" on each lower-case string,'
echo 'and a "no" on each upper-case string'
echo ''

for str in $list
do
    if [[ $str == [a-z]* ]]
    then
        echo yes on str = $str
    else
        echo no on str = $str
    fi
done

echo ''

for str in $list
do
    if [[ $str == [ab-z]* ]]
    then
        echo yes on str = $str
    else
        echo no on str = $str
    fi
done

echo ''
echo 'for a bash with the bug,'
echo 'note how the behavior changed in the last group,'
echo 'just because 'b' was listed in the glob [] pattern'

---------the output of the above script on RedHat 8.0 and 9.0 is:

BASH_VERSION = 2.05b.0(1)-release

no on str = aaa
yes on str = bbb
yes on str = zzz
yes on str = AAA
yes on str = BBB
yes on str = ZZZ

no on str = aaa
yes on str = bbb
yes on str = zzz
yes on str = AAA
yes on str = BBB
yes on str = ZZZ

the correct result for the above
should be a "no" on each lower-case string,
and a "yes" on each upper-case string

the correct result for the below
should be a "yes" on each lower-case string,
and a "no" on each upper-case string

yes on str = aaa
yes on str = bbb
yes on str = zzz
yes on str = AAA
yes on str = BBB
no on str = ZZZ

yes on str = aaa
yes on str = bbb
yes on str = zzz
no on str = AAA
yes on str = BBB
no on str = ZZZ

for a bash with the bug,
note how the behavior changed in the last group,
just because b was listed in the glob [] pattern

Fix:
        [Description of how to fix the problem.  If you don't know a
        fix for the problem, don't include this section.]





reply via email to

[Prev in Thread] Current Thread [Next in Thread]