Re: bash 4.1.2 and "broken" regular expression matching conditional operator (=~)

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

 



On Tuesday 26 January 2010, Roman Rakus wrote:
> Hi all,
> please take a look at bash faq section E - E14. Quoting:
> 
> E14) Why does quoting the pattern argument to the regular expression
>  matching conditional operator (=~) cause regexp matching to stop working?
[...]
> Please, take a look in your bash scripts and fix them.

Note also that in many cases it is possible to avoid using =~ altogether and 
use plain == and simple globbing (possibly with multiple tests), and in even 
more cases with extended globbing turned on.  In addition to fewer portability 
issues, globbing tends to be faster too.

If using extended globbing, just remember to reset extglob back to what it was 
if your script is a sourced, not executed one, e.g. something like:

    reset_extglob=$(shopt -p extglob)
    shopt -s extglob
    [[ "afoo" == *@(foo|bar|quux) ]] && echo hello
    # ...
    $reset_extglob

(We're not doing the reset in bash-completion yet, but eventually hopefully 
will, or find another way to circumvent modifying users' shopt states.)
-- 
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/devel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]
  Powered by Linux