[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: extglobs in case constructs
From: |
Greg Wooledge |
Subject: |
Re: extglobs in case constructs |
Date: |
Thu, 1 Oct 2009 10:33:28 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Thu, Oct 01, 2009 at 04:17:33PM +0200, Martin von Gagern wrote:
> #!/bin/bash
>
> shopt -s extglob
> f() {
> if [[ $v == a@(a|b|c)c ]]; then
> case $v in
> a@(a|b|c)c)
You're using extglobs inside a function, and extglob was enabled
at the time the function was delcared. The parser parsed them at that
time, decided that they are extended globs, and therefore that's what
they are.
Most people have the opposite problem -- they try to do this:
f() {
shopt -s extglob
if [[ $x = @(some|extended|glob) ]]; then
This does not work, because the parser parses the functions before the
extended globs are turned on. The solution is to move the
"shopt -s extglob" outside of the function, as you already have.