help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: extglob and ()/{}


From: Daniel Mills
Subject: Re: extglob and ()/{}
Date: Tue, 6 Apr 2021 11:52:25 -0400

On Tue, Apr 6, 2021 at 11:04 AM Peng Yu <pengyu.ut@gmail.com> wrote:

> On Tue, Apr 6, 2021 at 9:59 AM Daniel Mills <danielmills1@gmail.com>
> wrote:
> >
> >
> >
> > On Tue, Apr 6, 2021 at 10:56 AM Peng Yu <pengyu.ut@gmail.com> wrote:
> >>
> >>
> >> So the bottomline is not to use `shopt -s extglob` in () and {}
> >> blocks? If one wants to use `shopt -s extglob`, it must be outside of
> >> () and {} blocks?
> >>
> >>
> > It can be used in those blocks,
>
> By `shopt -s extglob`, I mean this text literally. But by "it", I
> think that you mean the option itself instead of the text literally.
> So we are talking about the same thing?
>
> > but it must be declared outside of them. And you cannot say use a
> subshell to make the option revert afterwards.
>
>
>
> --
> Regards,
> Peng
>

touch foobar foobaz; { shopt -s extglob; }; echo foo@(bar|baz)

That'll work. But it cannot be declared within the same compound command in
which it is used. That also goes for functions, if statements, loops, etc.
Ideally, if you want to use extglob in a script, just set it once at the
beginning of the script and be done with it. You'd be stretching to find a
place where
having it on where you don't need it would be a problem, IMO, anyway.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]