[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 2.0.0.23 (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
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
-DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin'
-DSYS_BASHRC='/etc/bash/bashrc'
-DSYS_BASH_LOGOUT='/etc/bash/bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS
-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
GNU/Linux
Machine Type: i686-pc-linux-gnu
Bash Version: 4.0
Patch Level: 33
Release Status: release
Description:
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.
Repeat-By:
-- Sample script -----------------------
#!/bin/bash
shopt -s extglob
echo -n "definition: "
shopt extglob
f() {
v=abc
shopt $1 extglob
echo -n " runtime: "
shopt extglob
echo -n " comparison uses extglob "
if [[ $v == a@(a|b|c)c ]]; then
echo "yes"
else
echo "no"
fi
echo -n " case uses extglob "
case $v in
a@(a|b|c)c)
echo "yes"
;;
*)
echo "no"
;;
esac
}
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
----------------------------------------
- extglobs in case constructs,
Martin von Gagern <=