This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bash regex tests wh'appen?

On 1/11/2007 8:07 AM, Dave Korn wrote:

I upgraded quite a lot of bash versions in one go, and one of my shell-scripts broke. I've reproduced it to a simple test case which shows that either regex tests have turned into non-reg-ex text matches, or that I've really misunderstood something here. I checked the last few release announcements and didn't see anything about the behaviour of =~ changing.

It's mentioned in /usr/share/doc/bash-3.2.9/CHANGES:

f.  Quoting the string argument to the [[ command's  =~
    operator now forces string matching, as with the
    other pattern-matching operators.

Also, I believe the unquoted pattern is already protected from expansion of special characters, so you don't have to worry about *.

/artimi/tools/cygwin/bin $ if [[ "foo.h" =~ "foo.h" ]] ; then echo "yes" ;

[[ "foo.h" =~ foo.h ]]

/artimi/tools/cygwin/bin $ if [[ "foo.h" =~ ".*foo.h" ]] ; then echo "yes" ;

[[ "foo.h" =~ .*foo.h ]]

/artimi/tools/cygwin/bin $ if [[ "foo.h" =~ "\.\*foo.h" ]] ; then echo "yes" ;

[[ "foo.h" =~ \.\*foo.h ]]

David Rothenberger                spammer? ->
GPG/PGP: 0x92D68FD8, DB7C 5146 1AB0 483A 9D27 DFBA FBB9 E328 92D6 8FD8

"The molars, I'm sure, will be all right, the molars can take care of
themselves," the old man said, no longer to me.  "But what will become
of the bicuspids?"
                -- The Old Man and his Bridge

-- Unsubscribe info: Problem reports: Documentation: FAQ:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]