On 10/6/15 8:27 AM, bash...@jonkmans.nl wrote: > 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.
This is fundamental to how the shell works. The shell always parses a complete command before executing any of it. A shell function definition is a compound command, so the shell parses the entire function definition at definition time rather than parsing it piece-by-piece on the fly at execution time. Since extglob changes parsing behavior to recognize the extended pattern matching operators -- which are otherwise syntax errors -- it needs to be enabled before parsing the function definition. > 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; ) It's not reasonable to expect the `shopt -s' to be executed as part of the function definition, without running the function at all. If you want to use the extended pattern matching syntax, you need to have extglob enabled before you try to parse any commands using it. That's just, as I said, fundamental. There is a compile-time option that enables extglob by default. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/