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: Koichi Murase
Subject: Re: About prepending strings to an array.
Date: Sun, 4 Feb 2024 00:28:16 +0900

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

>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



reply via email to

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