[Top][All Lists]

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

Inconsistent regex matching with =~ between bash 3.1 and 3.2

From: Scott Carpenter
Subject: Inconsistent regex matching with =~ between bash 3.1 and 3.2
Date: Sun, 08 Jul 2007 17:37:26 -0500
User-agent: Thunderbird (X11/20070326)

Hi, all. I hope this report is of some use -- I'm pretty inexperienced at GNU/Linux and Bash so I'm afraid this is going to sound horribly amateurish. But I think I've found something for you. (Or I'm simply about to demonstrate my crude understanding of regular expressions.)

I realize that regex handling has changed for the =~ operator from 3.1 to 3.2, and I'm trying to get my head around this while fixing a script that has broken in 3.2. I studied this thread:


And other pages and think I understand how I'm supposed to do things in 3.2, and can make my script work in 3.2. I'd like to make it be backwards compatible for 3.1, but I get different results for the example shown below (and errors on a variation).

In Ubuntu 7.04, $BASH_VERSION 3.2.13(1)-release, I try:

[[ ! $V =~ ^\.*/ ]] && echo not

And get "not", as expected. (The first part is true.)

In Ubuntu 6.10, $BASH_VERSION 3.1.17(1)-release:

The first part doesn't evaluate as true, so no output.

And this comes out as true:

[[ $V =~ ^\.*/ ]]

So, either my regex is all wrong (I'm trying to match from a dot at the start of the string up to the last forward slash), or might there be a problem with this 3.1 version of bash? Or door #3?

3.1 works as I expect if I try ^\./ as the regex (string starting with dot slash). (That is, it matches with ! for "one/two".)


The following works in 3.2 (produces "yes" for "./one/two"), but gets an error in 3.1:

[[ $V =~ (^\.*/) ]] && echo yes

unexpected argument `(' to conditional binary operator
syntax error near `(^'

Please let me know if more info would help. Again, I hope this is helpful, or at least isn't extremely annoying, and I apologize if it isn't/is.


reply via email to

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