Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: bashbug@jonkmans.nl Newsgroups: gnu.bash.bug Subject: extglob syntax error in function definition Date: Tue, 6 Oct 2015 14:27:32 +0200 (CEST) Lines: 39 Approved: bug-bash@gnu.org Message-ID: NNTP-Posting-Host: lists.gnu.org X-Trace: usenet.stanford.edu 1444138816 18180 208.118.235.17 (6 Oct 2015 13:40:16 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org,bash@packages.debian.org Envelope-to: bug-bash@gnu.org X-Virus-Scanned: clamav-milter 0.98.7 at smtpgw.dds.nl X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 91.142.252.201 X-Mailman-Approved-At: Tue, 06 Oct 2015 09:40:13 -0400 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11582 Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../. -I.././include -I.././lib -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall uname output: Linux ubak 3.13.0-30-generic #55-Ubuntu SMP Fri Jul 4 21:40:53 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu Bash Version: 4.3 Patch Level: 30 Release Status: release Description: The shell gives a syntax error when defining a function that uses the extended pattern matching operators. The man page does not mentin that extglob needs to be set at all. It does only say that it is needed for the !(...) construct. But i reckon then that setting extglob is also of influence on the other operators: ?(..) , *(...) , +(...) and @(...) . And indeed it is. This works: ## assuming extglob is off by default shopt -s extglob isnum () { case "$1" in [1-9]*([0-9])) return 0 ;; *) return 1 ;; esac; } shopt -u extglob Drawback is that the global extglob setting is being manipulated in the current execution environment. I would have expected that i could encapsulate the setting of extglob, by using a subshell-like function: shopt -u extglob isnum () ( shopt -s extglob; case "$1" in [1-9]*([0-9])) return 0 ;; *) return 1 ;; esac; ) But unfortunately this gives a syntax error. It seems that the parser does not, at definition time, recognize the extended pattern matching construct. Repeat-By: shopt -u extglob isnum () ( shopt -s extglob; case "$1" in [1-9]*([0-9])) return 0 ;; *) return 1 ;; esac; )