[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: string substitution broken since 5.2
From: |
Greg Wooledge |
Subject: |
Re: string substitution broken since 5.2 |
Date: |
Fri, 4 Nov 2022 07:33:03 -0400 |
On Fri, Nov 04, 2022 at 09:50:03AM +0100, Alex fxmbsw7 Ratchev wrote:
> On Fri, Nov 4, 2022, 08:56 Léa Gris <lea.gris@noiraude.net> wrote:
>
> > Le 03/11/2022 à 19:50, Chet Ramey écrivait :
> > > The option is enabled by default. If you want to restore the previous
> > > behavior, add `shopt -u patsub_replacement'.
> >
> > Having it enabled by default is not good, because it introduces
> > side-effects for existing scripts.
> >
>
> there is , imo , no sense to comply to outdated specs to not add few more
> of the infinite base features
>
> nevermind ..
There is no "spec" for this. It's not a POSIX feature. It's a bashism.
To be clear, we're talking about:
somecmd "${var//search/replace}"
where "replace" might be a string contained in a variable.
The reason this is an issue is because bash 5.2 has changed the default
behavior of this expansion in a way that not only changes the behavior of
existing scripts (possibly "breaking" them), but also makes it extremely
difficult to write one script that works across all bash versions.
In order to write a version-portable script that uses this feature,
now you have to choose between these two workarounds:
1) Put something like "shopt -u patsub_replacement 2>/dev/null || true"
at the top of your script.
2) Assign the result of the expansion to a temporary variable, and pass
the temp var to somecmd. Every. Single. Time.
- Re: string substitution broken since 5.2, (continued)
- Re: string substitution broken since 5.2, Koichi Murase, 2022/11/03
- Re: string substitution broken since 5.2, Greg Wooledge, 2022/11/03
- Re: string substitution broken since 5.2, Koichi Murase, 2022/11/03
- Re: string substitution broken since 5.2, Greg Wooledge, 2022/11/03
- Re: string substitution broken since 5.2, Greg Wooledge, 2022/11/03
- Re: string substitution broken since 5.2, Koichi Murase, 2022/11/03
Re: string substitution broken since 5.2, Thierry B., 2022/11/03
Re: string substitution broken since 5.2, Chet Ramey, 2022/11/03
- Re: string substitution broken since 5.2, Léa Gris, 2022/11/04
- Re: string substitution broken since 5.2, Alex fxmbsw7 Ratchev, 2022/11/04
- Re: string substitution broken since 5.2,
Greg Wooledge <=
- Re: string substitution broken since 5.2, Alex fxmbsw7 Ratchev, 2022/11/04
- Re: string substitution broken since 5.2, Greg Wooledge, 2022/11/04
- Re: string substitution broken since 5.2, Alex fxmbsw7 Ratchev, 2022/11/04
- Re: string substitution broken since 5.2, Chet Ramey, 2022/11/04
- Re: string substitution broken since 5.2, Alex fxmbsw7 Ratchev, 2022/11/04
- Re: string substitution broken since 5.2, Alex fxmbsw7 Ratchev, 2022/11/04
Re: string substitution broken since 5.2, Chet Ramey, 2022/11/04
Re: string substitution broken since 5.2, Martin D Kealey, 2022/11/04