More complete fix for bash regexp quoting bug.
authorRichard Jones <rjones@redhat.com>
Tue, 2 Mar 2010 10:34:20 +0000 (10:34 +0000)
committerRichard Jones <rjones@redhat.com>
Tue, 2 Mar 2010 10:34:20 +0000 (10:34 +0000)
Commit 457fccae1b665347 was not a complete fix, in that it
didn't work properly on RHEL 5 era bash (3.2.x).  For example:

  file=libntfs-3g.so.74
  [[ "$file" =~ ^lib(.*)\.so\.([0-9]+)\. ]] && \
    echo "lib${BASH_REMATCH[1]}.so.${BASH_REMATCH[2]}.*"

would on those old shells print:

  libntfs-3g.so.7.*

It seems the final \. was being treated as a plain period (ie.
match anything).

The only way to work around this incompatibility is to assign the
patterns to variables and match on those, ie:

  p='^lib(.*)\.so\.([0-9]+)\.'
  [[ "$file" =~ $p ]] && ...

This works in both old and new shells.


No differences found