help-bash
[Top][All Lists]
Advanced

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

Re: About prepending strings to an array.


From: Peng Yu
Subject: Re: About prepending strings to an array.
Date: Sat, 3 Feb 2024 14:07:05 -0600

On Sat, Feb 3, 2024 at 9:28 AM Koichi Murase <myoga.murase@gmail.com> wrote:

> 2024年2月4日(日) 0:07 Peng Yu <pengyu.ut@gmail.com>:
> > I don't remember this was the case in prior versions of bash. But I
> > don't have access to older versions of bash to double check. Does
> > anybody know whether bash has always been like this? Or bash has been
> > changed in the last few years that cause this change of behavior?
>
> This is the feature that *you* requested in the following email:
>
> https://lists.gnu.org/archive/html/help-bash/2021-04/msg00192.html
>

That was replacement. This current question is about prepending a string.
So I didn’t requested it. No wonder my code that used to work stopped
working.

>
> From Bash 5.2, unquoted & in the replacement of ${var/pat/rep}
> represents the "matched string" (just like sed 's/pat/rep/' and awk
> 'sub(/pat/,"rep")').
>
> $ var='hello'; echo "${var//?/(&)}"
> (h)(e)(l)(l)(o)
> $ sed 's/./(&)/g' <<< hello
> (h)(e)(l)(l)(o)
> $ awk 'gsub(/./, "(&)")' <<< hello
> (h)(e)(l)(l)(o)
>
> To make it behave like the previous versions of Bash, you can disable
> the feature by
>
> shopt -u patsub_replacement
>
> --
> Koichi
>
-- 
Regards,
Peng


reply via email to

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