Alex Chupin (achupin <achupin <at> cisco.com> writes: > > 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 > >
The entire right side of '=~' is considered a regular expression. The single quotes are being used in the match. If you remove them, it will work. Another alternative is to assign the regular expression to a variable and use it as the right side argument.