[Top][All Lists]

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

extglobs in case constructs

From: Martin von Gagern
Subject: extglobs in case constructs
Date: Thu, 01 Oct 2009 16:17:33 +0200
User-agent: Thunderbird (X11/20090827)

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: i686-pc-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib
-DSSH_SOURCE_BASHRC -march=prescott -O2 -ggdb
uname output: Linux server 2.6.30-gentoo-r5 #1 SMP PREEMPT Tue Aug 18
11:26:16 CEST 2009 i686 Intel(R) Pentium(R) 4 CPU 3.00GHz GenuineIntel
Machine Type: i686-pc-linux-gnu

Bash Version: 4.0
Patch Level: 33
Release Status: release


        I've found out that extglobs behave differently in different
        constructs. To avoid syntax errors, the always have to be
        enabled at parse time.
        For comparison constructs like ``[[ $v == a@(a|b|c)c ]]'' this
        is enough. For case constructs like ``case $v in a@(a|b|c)c)''
        the extglob shopt has to be set at runtime as well. This is kind
        of inconsistent.

        I've read several messages by Chet on the bug-bash mailing list,
        all claiming that the extglob shopt should change the parser
        only. In this case one would expect that setting it at the time
        a function gets defined should be enough, and that it shouldn't
        be necessary when the function gets executed. Case constructs
        inside a function render this assumption invalid.


        -- Sample script -----------------------


        shopt -s extglob
        echo -n "definition: "
        shopt extglob

        f() {

                shopt $1 extglob
                echo -n "  runtime: "
                shopt extglob

                echo -n "    comparison uses extglob     "
                if [[ $v == a@(a|b|c)c ]]; then
                        echo "yes"
                        echo "no"

                echo -n "    case uses extglob           "
                case $v in
                                echo "yes"
                                echo "no"


        f -s
        f -u

        -- Resulting output --------------------

        definition: extglob             on
          runtime: extglob              on
            comparison uses extglob     yes
            case uses extglob           yes
          runtime: extglob              off
            comparison uses extglob     yes
            case uses extglob           no


reply via email to

[Prev in Thread] Current Thread [Next in Thread]