On 12/17/10 12:00 PM, Harry Leitzell wrote:

> Bash Version: 4.1
> Patch Level: 5
> Release Status: release
> 
> Description:
> 
> Doing string matching based on word boundaries no longer works:
> 
> $ bash --version
> GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
> Copyright (C) 2005 Free Software Foundation, Inc.
> 
> $ cat test.sh
> input="foocombo foo foo bar bar foo bar some stuff foo" # the input
> expected="foocombo foo bar some stuff" # this what we expect
> for i in ${inp...@]}; do
>     [[ ! ${o...@]} =~ \\b"${i}"\\b ]] && old=( ${o...@]} $i )
> done
> for i in ${inp...@]}; do
>     [[ ! ${n...@]} =~ \b${i}\b ]] && new=( ${n...@]} $i )
> done
> echo "input:    $input"
> echo "expected: $expected"
> echo "old code: ${old[*]}"
> echo "new code: ${new[*]}"
> 
> $ bash test.sh
> input:    foocombo foo foo bar bar foo bar some stuff foo
> expected: foocombo foo bar some stuff
> old code: foocombo foo bar some stuff
> new code: foocombo foo foo bar bar foo bar some stuff foo

I don't know what version of Ubuntu you're running -- I'm not sure
which various versions of bash-3.2 are on Ubuntu 8, 9, or 10 -- but
using either your "old code" pattern after setting the `compat31'
option with shopt or the following

        wb='\b'
        ${wb}${i}${wb}

will work.  This is one of the reasons the compat31 option, and the
notion of a shell compatibility level, exists.  A shell variable will
usually do the job, too.

Item 33 in COMPAT and item E14 in the Bash FAQ cover the issue in
more detail.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/

Reply via email to