[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
extglob syntax error in function definition
From: |
bashbug |
Subject: |
extglob syntax error in function definition |
Date: |
Tue, 6 Oct 2015 14:27:32 +0200 (CEST) |
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; )
- extglob syntax error in function definition,
bashbug <=