Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11587

Re: extglob syntax error in function definition

From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: extglob syntax error in function definition
Date 2015-10-08 08:46 -0400
Message-ID <mailman.11.1444308415.4386.bug-bash@gnu.org> (permalink)
References <20151006122732.3006A264E1A@mail.jonkmans.nl> <20151008034420.GA7819@ma.sdf.org>

Show all headers | View raw


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.

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: extglob syntax error in function definition Greg Wooledge <wooledg@eeg.ccf.org> - 2015-10-08 08:46 -0400

csiph-web