commit:     532b31730c687c6ef70b74326f7a1bb2f6e569f0
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Thu Jan  1 20:58:17 2026 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Thu Jan  1 21:13:25 2026 +0000
URL:        https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=532b3173

ebuild-writing/eapi: Add item for Bash 5.2 patsub_replacement

Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>

 ebuild-writing/eapi/text.xml | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/ebuild-writing/eapi/text.xml b/ebuild-writing/eapi/text.xml
index ccfaf0e..a643c6d 100644
--- a/ebuild-writing/eapi/text.xml
+++ b/ebuild-writing/eapi/text.xml
@@ -1549,6 +1549,30 @@ ${ local X=12345; echo $X; }
 ${| REPLY=12345; }
 </codesample>
       </li>
+
+      <li>
+        <p>
+        Pattern substitution now duplicates a common <c>sed</c> idiom:
+        If the <c>patsub_replacement</c> shell option is enabled (which it is
+        by default), any unquoted <c>&amp;</c> in the replacement string is
+        replaced with the portion of the string that matched the pattern.
+        </p>
+        <p>
+        For instance:
+        </p>
+<codesample lang="ebuild">
+var="foobar"
+echo "${var/foo/&amp;123}"
+</codesample>
+        <p>
+        will print <c>foo123bar</c>, i.e. the <c>&amp;</c> in the replacement
+        string is replaced with the string <c>foo</c> that matched the pattern.
+        </p>
+        <p>
+        A backslash can be used to escape the <c>&amp;</c> and insert a literal
+        <c>&amp;</c> in the replacement string.
+        </p>
+      </li>
     </ul>
   </dd>
 </dl>

Reply via email to