From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id ABF9B2356C for ; Tue, 13 Feb 2024 03:24:27 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1707791067; b=mPxBew7QMOA3lJ6JTuquXOksDwK7KojHV68jN5ifZXtzZWlNlR/V30EqraPFSh3m/dPqhrHKPL HbjLFuyVaEuR7IbmBObvqis0VVsrjgVsl6Luz+d4FQz/xc0mNnSWwFXbp3gP3Zm4hJfecpei5O Xr7+tqRbch9AD8FjvqvS03rNQ+isg9+IJKkDdBjv5VWCD9Abvxh/6OoX2HeJJYulzrgwmZQRBn 7lo+K0Yll+DAngkpA6b/V8Ke4EuKkDq8fpASUVSmov0+Q1vTyUZzY3tjsQpEAdTd6qPDuILBOf Ai6/F70N2Kvq6pC/7fnvlOqgsOx6pchvKUHsbTRhaOwT2g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f178.google.com) smtp.remote-ip=209.85.208.178; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1707791067; bh=BFeiWd799Xmb2XG2KI+Y1ib2WyTvySObIReLUt04bSo=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=UpS1PSsOCjXV/wlRSwbpetrglBvrX7AaeAdDz2xRkRwGwPlOCvc94nK7x/a8sGRB1okm+ovPYS Ul7tylSYdl4u7aY8M7E/Pr6n+FBQicCS2nj/ADk4BLJj189SEbWhlT3o6EnGdhWrez6fqIGuyA ic+986hIEEX5cPaFbGvQXbbLenWjfJNSnnCB9k8g0NpGMrlihQaVc+Rm3MBDf6wQF1/irhY1af 2avCstHerNbEItWKByBx8AJbIdD/YdL+2QsbnZIpSZuRUPqwZEodde0WNbHFG9MMsFlci5YGc5 yAbG6Xz9L/OnIzF0Ro991FFJsoUY4yVSqh+SMEExd8348A==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=DOQxB7xwJNxYQbxrNnnK/5lQNJrNjaY94zi2JdiHea0=; b=U/bA9+Z6OZnx0iH170qejjyn5J Zhnrki18Wew6s77lnoJiC7s4C88oUQ26hNiwOL3FTDKDHP9HStXA78GJ4xf5IkJYB3K73TZZNvz1L tL3mfYnRj8zHWImQNxsDZTCYyaTiepHnATuf+B41MekFA8Nu74w4Rb0sA+YKINWE7Z0wfVrfve4HZ EuzOk6xdZyKjh73yAJAgOPA561ROYGF8UWX6Zpur+4pWrnDbI/WzQFczQdf2P+s3X8/XH6SPjjOgA iS5iOO/TYxX19xjZWBkWI+4ueJhx8BLY0BPgd7/ENYnB+rUBhbhO/OOTNgDfJcHeRBQaYPl8gs5tE Hxop9uNA==; Received: by zero.zsh.org with local id 1rZiTC-000ACJ-C4; Tue, 13 Feb 2024 02:24:26 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f178.google.com) smtp.remote-ip=209.85.208.178; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f178.google.com ([209.85.208.178]:52403) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rZiSd-0009Wx-NO; Tue, 13 Feb 2024 02:23:52 +0000 Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d0e5212559so32347751fa.0; Mon, 12 Feb 2024 18:23:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707791030; x=1708395830; darn=zsh.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DOQxB7xwJNxYQbxrNnnK/5lQNJrNjaY94zi2JdiHea0=; b=f1N5g0mlOQ5R+vbUkbLU0At/4EtiAs9Ov+UAEfZg/CeVIO7fB8SCEkspK4zBq476q+ jW1JoYgF6zXFh7XqHkuVOu9ZdaSGIUXNeFDdct7/obLdN5J3rzM4YDJ4TM/uliuBtJpB QNqioGCUH6hh41S5ZYrfqG3RyRjbqOvTpsAcoAYhFLt9D2NZoNVdMEjPWzx20PZtEEJT dWJ4YSDxx0NLUWq/409oQMAwebZTtW2j47/coWvezj0pF3i5fw8halVofPk3OU2/CJ+R 4duj7xBYzoLMEPTHBlfRuwJKkjmEMy3Y9/2/n3Q9leQq2qbrNuDhGU2R0Z6GooiIDOhX KIxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707791030; x=1708395830; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DOQxB7xwJNxYQbxrNnnK/5lQNJrNjaY94zi2JdiHea0=; b=IJf4azos5pHjcSKdpNzMGzH+qQcsLs/EoAHx0oplq1KoxdnVxEH8tJOABBDdMPe1RG ojoikB5pCvNpQrdWs1M5VBWTQdLqc9RLeRWEUIHxEG9NqEBON6zkDGF9slR3Rrl2iLVH +8YT3P4Dve9r+ctIcp8t/1bEPdXhtovL4Rl92JRM/YC+7tNngScyWR04ef87l/M0taYu 0uSa1kEu44nz4XEJRhFl2PLV9FLIG2PnV413KE3S5wzmSjTIPsVliGhrVdyQBPzC46XQ Z1BeDGU9RS8A1rOzbAzmrBWc0AHvnTLDB7fl8kaiEiZS+fjxv5JiLys5U012wj5ZlycT F2Ug== X-Gm-Message-State: AOJu0Yw5tycbqsSkkFtlwJEpwHXtlXFv4oEfvI5HXHXasuT/L6U55idU BACwQqRRlBZt6VAIYLenYrJtiUzCFzo6GRLVcwMQZefDRtnns2e/ptqszd5DlvJyeK1oWi3844i /Z0vDT5yM8hKbKWnlEkCzp8GECDQBe5OhXns= X-Google-Smtp-Source: AGHT+IEHqNAd5vSFZTQrhXuTi8Ye4lHDbojDWKEr9HUWrcN+jK2evBhE4arZ/NWIZAj6R4ouOO5TLz0Zh4SfEzPNFe0= X-Received: by 2002:a2e:7d11:0:b0:2d0:e4e8:c999 with SMTP id y17-20020a2e7d11000000b002d0e4e8c999mr4957627ljc.3.1707791029644; Mon, 12 Feb 2024 18:23:49 -0800 (PST) MIME-Version: 1.0 References: <49716226-f212-491a-94d9-cfdb83b38aab@bashsupport.com> <4521f970-04dd-4521-a450-44c365adf625@app.fastmail.com> In-Reply-To: <4521f970-04dd-4521-a450-44c365adf625@app.fastmail.com> From: "Mark J. Reed" Date: Mon, 12 Feb 2024 21:23:36 -0500 Message-ID: Subject: Re: Is ":G" of ${name:s/l/r/:G} actually supported? To: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= Cc: Joachim Ansorg , zsh-users@zsh.org Content-Type: multipart/alternative; boundary="000000000000ac333806113a1593" X-Seq: 29663 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: --000000000000ac333806113a1593 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > In addition to the following operations, the colon modifiers described in the section `Modifiers' in the section `History Expansion' can be applied: for example, ${i:s/foo/bar/} performs string substitution on the expansion of parameter $i. That's a very helpful snippet that I missed. Thanks. Sorry for the misinformation. On Mon, Feb 12, 2024 at 4:52=E2=80=AFPM Lawrence Vel=C3=A1zquez wrote: > On Mon, Feb 12, 2024, at 12:11 PM, Mark J. Reed wrote: > > Well, that was a shorter reply than I intended. But you should be able > > to see that the section you linked (14.1.4 Modifiers) is part of 14.1, > > History Expansion. Those modifiers don't apply to parameter > > substitution. > > They do. > > % var=3Dfoobar > % print -- $var:s/o/x > fxobar > > This is documented in zshexpn(1) under "Modifiers": > > After the optional word designator, you can add a sequence > of one or more of the following modifiers, each preceded > by a `:'. These modifiers also work on the result of > _filename generation_ and _parameter expansion_, except > where noted. > > and "PARAMETER EXPANSION": > > In addition to the following operations, the colon modifiers > described in the section `Modifiers' in the section `History > Expansion' can be applied: for example, ${i:s/foo/bar/} > performs string substitution on the expansion of parameter $i. > > > > For doing replacements with parameter expansion, you can just use the > > slash modifier. One / replaces the first occurrence, two //s does all > > of them: > > > >> *$ value=3D/dir/subdir/file.csv* > >> *$ echo ${value//dir/_G}* > >> */_G/sub_G/file.csv* > > > > That's not a zsh-specific feature; ksh and bash have it as well. Zsh > > likely has a different mechanism to accomplish the same thing, but I've > > not needed it so am not familiar with it. > > The :s and :gs history modifiers are similar but not exactly so. > Among other things, they perform literal searches by default, allow > referring to the matched text with "&", and apply nested expansions > differently. > > > >> On Mon, Feb 12, 2024 at 9:19=E2=80=AFAM Joachim Ansorg > wrote: > >>> Hi, > >>> I was reading about modifiers on page > >>> https://zsh.sourceforge.io/Doc/Release/Expansion.html#Modifiers, > which says: > >>> > >>> > The forms =E2=80=98gs/l/r=E2=80=99 and =E2=80=98s/l/r/:G=E2=80=99= perform global substitution, > i.e. substitute every occurrence of r for l. Note that the g or :G must > appear in exactly the position shown. > >>> > >>> But zsh 5.9 doesn't seem to support this: > >>> > value=3D"/dir/subdir/file.csv" > >>> > echo ${value:s/dir/_/:G} > >>> zsh: unrecognized modifier `G' > > It doesn't work on zsh 4.3.11 either, which means it hasn't worked > for at least 13 years. (This probably says something about the > prevalence of applying :s/l/r/:G to parameter expansions.) > > > >>> Is ":G" actually supported or is the documentation outdated here? > > I can't say for sure, but this feels like a bug to me. > > > -- > vq > --=20 Mark J. Reed --000000000000ac333806113a1593 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 In addition to t= he following operations, the colon modifiers
=C2=A0 =C2=A0 =C2=A0 =C2=A0= described in the section `Modifiers' in the section `History
=C2=A0= =C2=A0 =C2=A0 =C2=A0 Expansion' can be applied: for example, ${i:s/foo= /bar/}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 performs string substitution on the e= xpansion of parameter $i.

That's a very helpful snip= pet that I missed. Thanks. Sorry for the misinformation.


On Mon, Feb 12, 2024 at 4:52=E2=80=AFPM Lawrence Vel=C3=A1zquez <larryv@zsh.org> wrote:
On Mon, Feb 12, 2024, at 12:11 P= M, Mark J. Reed wrote:
> Well, that was a shorter reply than I intended. But you should be able=
> to see that the section you linked (14.1.4 Modifiers) is part of 14.1,=
> History Expansion. Those modifiers don't apply to parameter
> substitution.

They do.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 % var=3Dfoobar
=C2=A0 =C2=A0 =C2=A0 =C2=A0 % print -- $var:s/o/x
=C2=A0 =C2=A0 =C2=A0 =C2=A0 fxobar

This is documented in zshexpn(1) under "Modifiers":

=C2=A0 =C2=A0 =C2=A0 =C2=A0 After the optional word designator, you can add= a sequence
=C2=A0 =C2=A0 =C2=A0 =C2=A0 of one or more of the following modifiers, each= preceded
=C2=A0 =C2=A0 =C2=A0 =C2=A0 by a `:'.=C2=A0 These modifiers also work o= n the result of
=C2=A0 =C2=A0 =C2=A0 =C2=A0 _filename generation_ and _parameter expansion_= , except
=C2=A0 =C2=A0 =C2=A0 =C2=A0 where noted.

and "PARAMETER EXPANSION":

=C2=A0 =C2=A0 =C2=A0 =C2=A0 In addition to the following operations, the co= lon modifiers
=C2=A0 =C2=A0 =C2=A0 =C2=A0 described in the section `Modifiers' in the= section `History
=C2=A0 =C2=A0 =C2=A0 =C2=A0 Expansion' can be applied: for example, ${i= :s/foo/bar/}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 performs string substitution on the expansion o= f parameter $i.


> For doing replacements with parameter expansion, you can just use the =
> slash modifier. One / replaces the first occurrence, two //s does all =
> of them:
>
>> *$ value=3D/dir/subdir/file.csv*
>> *$ echo ${value//dir/_G}*
>> */_G/sub_G/file.csv*
>
> That's not a zsh-specific feature; ksh and bash have it as well. Z= sh
> likely has a different mechanism to accomplish the same thing, but I&#= 39;ve
> not needed it so am not familiar with it.

The :s and :gs history modifiers are similar but not exactly so.
Among other things, they perform literal searches by default, allow
referring to the matched text with "&", and apply nested expa= nsions
differently.


>> On Mon, Feb 12, 2024 at 9:19=E2=80=AFAM Joachim Ansorg <mail@bashsupport.com= > wrote:
>>> Hi,
>>> I was reading about modifiers on page
>>> https://zsh.sourceforge.= io/Doc/Release/Expansion.html#Modifiers, which says:
>>>
>>> >=C2=A0 =C2=A0The forms =E2=80=98gs/l/r=E2=80=99 and =E2=80= =98s/l/r/:G=E2=80=99 perform global substitution, i.e. substitute every occ= urrence of r for l. Note that the g or :G must appear in exactly the positi= on shown.
>>>
>>> But zsh 5.9 doesn't seem to support this:
>>>=C2=A0 =C2=A0> value=3D"/dir/subdir/file.csv"
>>>=C2=A0 =C2=A0> echo ${value:s/dir/_/:G}
>>>=C2=A0 =C2=A0zsh: unrecognized modifier `G'

It doesn't work on zsh 4.3.11 either, which means it hasn't worked<= br> for at least 13 years.=C2=A0 (This probably says something about the
prevalence of applying :s/l/r/:G to parameter expansions.)


>>> Is ":G" actually supported or is the documentation o= utdated here?

I can't say for sure, but this feels like a bug to me.


--
vq


--
Ma= rk J. Reed <mar= kjreed@gmail.com>
--000000000000ac333806113a1593--