On Sat, 24 Nov 2012 21:08:16 +0000, "Alex Chupin (achupin)" <achu...@cisco.com> 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.