On Tue, 2023-06-13 at 11:07 +0200, Ulrich Mueller wrote:
> > > > > > On Tue, 13 Jun 2023, Michał Górny wrote:
> 
> >  _pypi_normalize_name() {
> >     local name=${1}
> > -   local shopt_save=$(shopt -p extglob)
> > -   shopt -s extglob
> > +   local prev_extglob=-s
> > +   if ! shopt -p extglob >/dev/null; then
> > +           prev_extglob=-u
> > +           shopt -s extglob
> > +   fi
> >     name=${name//+([._-])/_}
> > -   ${shopt_save}
> > +   shopt "${prev_extglob}" extglob
> >     _PYPI_NORMALIZED_NAME="${name,,}"
> >  }
> 
> In principle you could also do something like this:
> 
>       if shopt -pq extglob; then
>               name=${name//+([._-])/_}
>       else
>               shopt -s extglob
>               name=${name//+([._-])/_}
>               shopt -u extglob
>       fi
> 
> It duplicates one line of code, but saves a variable and IMHO the code
> would be easier to understand.
> 

I was thinking about this but I really dislike repeating the logic
twice.  In my opinion, having such block would be confusing: why are
there two logics for extglob on and off?  Why are both the same?  Is
this some mistake?

Even though this is unlikely, someone could actually end up creating
a missync there, and things would go downhill from there.

-q is a good idea though.

Ideally, we'd avoid extglob at all but I can't think of another pure
bash way of doing this.

-- 
Best regards,
Michał Górny


Reply via email to