bug-bash
[Top][All Lists]
Advanced

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

Re: problem with extended regular expression in bash 4.1


From: Davide Brini
Subject: Re: problem with extended regular expression in bash 4.1
Date: Sat, 24 Nov 2012 23:26:04 +0100

On Sat, 24 Nov 2012 21:08:16 +0000, "Alex Chupin (achupin)"
<address@hidden> wrote:

> Dear All,
> 
> Can someone shed light on the difference in behaviour of bash 4.1. and
> 3.25? I am out of ideas. 
> 
> Regards,
> Alexander Chupin
> 
> $ bash --version; s=12345;if [[ "$s" =~ '^[0-9]+$' ]]; then echo it is a
> number; else echo it is NOT a number; fi GNU bash, version
> 4.1.2(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2009 Free
> Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later
> <http://gnu.org/licenses/gpl.html> This is free software; you are free to
> change and redistribute it. There is NO WARRANTY, to the extent permitted
> by law. it is NOT a number
> 
> 
> $ bash --version; s=12345;if [[ "$s" =~ '^[0-9]+$' ]]; then echo it is a
> number; else echo it is NOT a number; fi GNU bash, version
> 3.2.25(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2005 Free
> Software Foundation, Inc. it is a number

It changed between bash 3.1 and 3.2, documented in the NEWS file. There is
a "compat31" option that can be turned on to restore the 3.1 behavior.

See here: http://stackoverflow.com/questions/218156/bash-regex-with-quotes
In any case, keeping the pattern in a variable is safer and works with
all versions of bash.

-- 
D.



reply via email to

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