[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem with extended regular expression in bash 4.1
From: |
Lawrence Steeger |
Subject: |
Re: problem with extended regular expression in bash 4.1 |
Date: |
Sat, 24 Nov 2012 22:29:30 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
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.