From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 601 invoked from network); 2 Dec 2022 00:53:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 2 Dec 2022 00:53:02 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1669942382; b=lh0Emxf/QMqEGE/8UK98m5tfwDMz9mPlObuTOuYiVyucyXhH9cam3pmTodvgH+C5vDgUOiKeZm B+tdC1mvkJFZ0YO2jE8P/TRxKDLC7OSU1Df/EaRthpJVqq5bo4IRIH8c/y/MVWU/d4jsCOpDAG M4KEs5D5rZ8J/s9UEFD6cPiBboBNm2omYAQECz66qYSR4B13+OBm625q4ebgkv5FoqwLLiIaYy 3Qt/pUQh5mdq3W6qO3baCQYzS4LZdJBv3NYKRFrPK1nTXwQ0XTSNm7FbLELbnaSf6TfVfWfCyR 4vo6vnuW/wAGwVG7FBFKAri+CQaST5yDjtm4AxA3Yr+b2g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mout.gmx.net) smtp.remote-ip=212.227.17.20; dkim=pass header.d=gmx.de header.s=s31663417 header.a=rsa-sha256; dmarc=pass header.from=gmx.de; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1669942382; bh=wkuleuGRcFTCDgqPqW6g/8USFvXZvj4910i3N7YKPCs=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:In-Reply-To:Content-Type: MIME-Version:References:Reply-To:Message-ID:Subject:To:From:Date: DKIM-Signature:DKIM-Signature; b=P6PzVLEQuJaEa291MoxW8gSlSNSG7NihQmPOJo0dNvjKNN9bJGwobbim/TKPDzJCRxTDysQJQq erJd6TCT9CjvzZTilhVdXe2MlEYxVsXU0wkkgPvV8zKI86OxGzEpxKzwfZBXhjFxzaQ2JATxxw yvA3oU7Uu4OHb9fRxoTHuv7ol4OzDLvbxZEv4ahtRGy8+jNkL1dwPATVV5rlu7kMID+ShFe0Z9 usDRlJqhV4IIbGT3HL85+K4ODPOpeoW3LcbVuKUdz1nwcxDE2LI4qikKh+zQDRigFHA3OI/OXE 8dTjGBvXeNUh1oMa7PhgSDul9/D1MflUOy8nQjiWRciUqg==; 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-Transfer-Encoding:In-Reply-To :Content-Type:MIME-Version:References:Reply-To:Message-ID:Subject:To:From: Date:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=UppjGoSfhcCtGgNcZ9r7RlnzK3tcf0WuKO5f0pxV+9I=; b=IOuSDXhSUnJLnOK9hbMVKXUr5w +rbwrzarmdkwkvCv3Li4aHUjZBsO2CXVD5mW6ko3QSizJTieVf97YNIn7+MG7CjZU8u0XmCMfhhzs jdw2nKmzL24KenGcXnzcad4/YgWV7bggzoGjiSbcGuiMPHa5FZ86vRx2oJLtLc+uO5Sb5r+x9lsVc O6uNLeCAJOCy7+yijH9KkCVfv7Knjvc2uD9gzV32n7kegO8Ro7PC3pp3iWP4klumZxmXUdXRxTPqC K1JEK9vskQMVs8CJPzRa3nOmxg94NfZl79XV5eBwWLqsk379dehfzFiQsyA6C0CBV33QP8hNqzWkB nQzaLKWA==; Received: by zero.zsh.org with local id 1p0uIX-000Izt-8A; Fri, 02 Dec 2022 00:53:01 +0000 Authentication-Results: zsh.org; iprev=pass (mout.gmx.net) smtp.remote-ip=212.227.17.20; dkim=pass header.d=gmx.de header.s=s31663417 header.a=rsa-sha256; dmarc=pass header.from=gmx.de; arc=none Received: from mout.gmx.net ([212.227.17.20]:40129) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1p0uHe-000IKm-T1; Fri, 02 Dec 2022 00:52:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1669942326; bh=wkuleuGRcFTCDgqPqW6g/8USFvXZvj4910i3N7YKPCs=; h=X-UI-Sender-Class:Date:From:To:Subject:Reply-To:References: In-Reply-To; b=Bmy4l0FAbXMqDK7OJ2gYREt+iub2gdvMGb4x4shflDSL1GD4JFzBi40wcQeo8smVb 1r8bAdWk7YMv+miGdwWw7FH2KjCbuZ1kG+RUniLYT/HcG8PR7RFrDSf1q7GZ+puby0 paTyjCqOJyFHUjCXI9/HlgW/KKmuLD+lCGo2ODF4CfQJ8X4mdAqvoQycA0bZCgrahx a8O5FslXKHoDEI3+6Yq3JVxSreITIs/bfu5IswsOmwX3Yja+tMpR40PKjNL5mARRL9 qAuLnJenpkVjcrcEgPzqHICvmUi596ZWKrWmVtnIJycp71z047ViCkej9qMFhxMRV7 wrg3+e3i8F1Nw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from zitrone.obstwiese ([46.223.163.213]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MWigq-1pTTmH436O-00Wzrt for ; Fri, 02 Dec 2022 01:52:06 +0100 Received: from luthien by zitrone.obstwiese with local (Exim 4.94.2) (envelope-from ) id 1p0uHa-0001Tl-RA; Fri, 02 Dec 2022 01:52:02 +0100 Date: Fri, 2 Dec 2022 01:52:02 +0100 From: Dominik Vogt To: zsh-users@zsh.org Subject: Re: Modifiers and parameter expansion? Message-ID: Reply-To: dominik.vogt@gmx.de Mail-Followup-To: zsh-users@zsh.org References: <1dcdd69c-ce29-921f-f0f0-6862f68b62a6@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:kKsTTg9n2vaB2KMv2LmYc4AeTW4Op9vC7zU6QcA0wgS4VQhG+DY oWAqhkjEUtStQjQB7z3eF/6S7IHlwKSpKviXfTqZws6bHKs8LVYLf3Kr199ULZP/fCyPWtu WANuJN6/w5wN2DtqlNBWAsdDCMc0D9yKEft2FJLa0PjMDaeaOeWT4niqKLgO1acjQNJD4+s pc6YN5eUXf7QVxU18XMBw== UI-OutboundReport: notjunk:1;M01:P0:8N8yH3O1XcE=;A9SzXwMgHTpOgKfLezaVWNHEzwv SkW8AwkMnQ48NTVa6iQVYMIP6evbmHnVVcuiw4t+guelyrFvtOcRgC8YgqqRuALMZ8YGIfypi nKUkzpunFTiM1Ys+sRteyABh8xiHIb6zbjA5R0ZB8VrWaTF5QUaLJ2UxXWfcJqdSIGG9JfngC gg2QNIOcDsX0Jyk63dTxR1+zBfBFnFmn8+npkRY+5F5+0+oQc3Z4c3GhB0FzPICo3YoCtsla+ 1P0VVxWiWp4M9FAIW/zt1prX4PEJfAHEYsnYdwnmaDEMIrWvlg8ZMEXGnjcOKeCi+rcY0k8Qh oC+UZsGuNJVTN2qolHpWNZN4U9Z4tgodvOogCE4iOAdHLywnjPYvHt9cVB9kDFy9X4lhrOPWx oFRH+AnSbHJ3kJe4ViwRW777w3eYkaKtJ4cNrAcStaGgHD0PptcbGvP72sMXZCcdYMLz400H/ ZrmQOTnLRFuOoE0DnsZspDxu+O9Y7FnDjXsKfpog3JVU8h3yxEEmzZcRmu0FlVZClCsfjwtYx 3rUiVo6T8woegcfk//RtxWBeZNdNBwa0ow1g3DzW+fbrSSnEFqEytV+Y9t4AEuuy6pn3yYAQ9 w1De7gxDVcqlOWdRXM2CFhjt/ywi38rgX7+keapld6u+v8P8X+SBV0hsROpFcIex+50c7jP8D 9D2LjEGHqx7onxy4ghFJn4WoBg/Fk1HdU7B93+6nd+nfYNrwk5soV7k5n+Q4utJy7DGBuRz3P so1IBhxw4NMf6gkmgW0nzxSzLvRQTAVoLqqPIqJqLQhCCRJx7inRjQiiVE5x5yIn8khhGWiwH 4wxeEa6DagbTo+cTQa1g5SwXW/QuzsI5aYcgviIDRL52D+vCwkx15nfr3Xzfpdxg3RKx1qzo9 wMAhm65nYH+BDm+Txx5jxQltHeY43VySL9mxJ0iNeQrlGL/tBzBUc+O0EXA+vSkQVACRmSmf/ sy/eOA== Content-Transfer-Encoding: quoted-printable X-Seq: 28470 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: On Thu, Dec 01, 2022 at 03:42:27PM -0800, Bart Schaefer wrote: > On Thu, Dec 1, 2022 at 2:39 PM Dominik Vogt wrote: > > > > I cannot find anything in the man page that suggest it would work > > this way. All occurences of modifiers used with parameters put > > them in braces. The rule from the man page: > > > > 7. Modifiers > > That rule is just telling you at what point during all possible > expansions the effects of modifiers come into play, it's unrelated to > the syntax. Okay. Why are "%" "%%" "#" "##" "/" "//" refered to in this section? They're not called "modifiers" anywhere else. Maybe the rule should be named "Pattern replacements and modifiers"? > In the Parameter Expansion section > > ${NAME} > The value, if any, of the parameter NAME is substituted. The > braces are required if the expansion is to be followed by a letter, > digit, or underscore that is not to be interpreted as part of NAME. > In addition, more complicated forms of substitution usually require > the braces to be present; exceptions, which only apply if the > option KSH_ARRAYS is not set, are a single subscript or any colon > modifiers appearing after the name, or any of the characters '^', > '=3D', '~', '#' or '+' appearing before the name, all of which work > with or without braces. > > Note "exceptions ... are a single subscript or any colon modifiers > appearing after the name ..." The braces are required unless(1) they are not(2) required unless(3) some option is not(4) present. Quadruple negative. All I understand is that it's trial and error to figure out whether braces are required. Let's see: $ rm -rf tmp $ mkdir tmp $ cd tmp $ touch a b $ unsetopt KSH_ARRAYS $ echo ^a =3Dls b /bin/ls <-- matches man page $ echo ~a zsh: no such user or named directory: a <-- matches man page $ X=3Dabc; echo $X:u $X[2] ABC B <-- matches man page $ echo $+X $#X 1 3 <-- matches man page $ setopt KSH_ARRAYS $ echo ^a =3Dls b /bin/ls <-- not what the man page says $ echo ~a | zsh: no such user or named directory: a <----| $ X=3Dabc; echo $X:u | ABC <-- ok | $ echo $X[2] | zsh: no matches found: ABC[2] <-- ok | $ echo $+X $#X | 1 3 <-------------- =2D- This section could be split in two, to improve readability: ${NAME} The value, if any, of the parameter NAME is substituted. This form is required if the characters following the closing brace would be interpreted as part of the substitution otherwise. $NAME The value, if any, of the parameter NAME is substituted. A letter, digit or underscore after NAME is interpreted as part of NAME. The characters '^', '=3D', '~', '#' or '+' appearing before NAME work without braces. A single subscript or any colon modifiers appearing after NAME work only if the KSH_ARRAYS option is not set. All other kinds of complex substitutions require the form with braces. Using braces is always safe. And adding a short section about modifiers may be a good idea: PARAMETER EXPANSION ... Modifiers Modifiers preceded ba a `:' as described in the section `Modifiers' in the section `History Expansion' can be applied. If the KSH_ARRAYS option is set, braces are required to use modifiers. Parameter Expansion Flags ... It's a slight duplication of information, but much easier to find for normal mortals. (Note that the `:' is there on purpose to make it easier to find when searching through the man page.) Ciao Dominik ^_^ ^_^ =2D- Dominik Vogt