[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: extglob syntax error in function definition
From: |
Greg Wooledge |
Subject: |
Re: extglob syntax error in function definition |
Date: |
Thu, 8 Oct 2015 08:46:15 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Wed, Oct 07, 2015 at 10:44:20PM -0500, Eduardo A. Bustamante López wrote:
> > Repeat-By:
> > shopt -u extglob
> > isnum () ( shopt -s extglob; case "$1" in [1-9]*([0-9])) return 0 ;;
> > *) return 1 ;; esac; )
>
> Remember that bash parses and interprets the script line-by-line. If you want
> to change the parser's operation (for example, have it recognize the extglob
> patterns), you have to do it in a different line than where you're using the
> special syntax.
Even more: bash parses an entire function all at once. If you want
extglob syntax to be permitted inside a function, the extglob option
must be turned on BEFORE the function is parsed. You can't flip it
inside a function.
The normal recommendation is that you should put shopt -s extglob
right at the top of your script, directly beneath the shebang.
#!/usr/local/bin/bash
shopt -s extglob
That way extglob is enabled for the entire script, functions and all.
I'm not aware of any negative consequences for doing this. In fact,
bash has a compile-time option to enable extglob. This isn't the
default (yet), but perhaps some day it will be.