From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29550 invoked by alias); 4 Nov 2016 10:24:37 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22083 Received: (qmail 27185 invoked from network); 4 Nov 2016 10:24:37 -0000 X-Qmail-Scanner-Diagnostics: from mailout1.w1.samsung.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(210.118.77.11):SA:0(-2.3/5.0):. Processed in 0.5209 secs); 04 Nov 2016 10:24:37 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts) X-AuditID: cbfec7f2-f79556d000002c42-57-581c61ddf313 Date: Fri, 04 Nov 2016 10:24:25 +0000 From: Peter Stephenson To: zsh-user Subject: Re: What's the 'word' in parameter relpacement expansion? Message-id: <20161104102425.5df2b0c6@pwslap01u.europe.root.pri> In-reply-to: <20161104090009.GA22682@localhost.localdomain> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDIsWRmVeSWpSXmKPExsWy7djP87p3E2UiDFbs57PYcXIlowOjx6qD H5gCGKO4bFJSczLLUov07RK4Mg7dm8dUsEK04sec96wNjPMFuxg5OSQETCS2/n7NBGGLSVy4 t56ti5GLQ0hgKaPExs9trBBON5P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XH1x2Y2iJkTGCWuXd/BApLg F9CXuPr3ExPEefYSM6+cYYRoFpT4MfkeWA2zgJbE5m1NrBC2vMTmNW+ZIV5Ql7hxdzf7BEbh WUhaZiFpmYWkZQEj8ypGkdTS4tz03GJDveLE3OLSvHS95PzcTYzAGNp27OfmHYyXNgYfYhTg YFTi4Z3hJx0hxJpYVlyZe4hRgoNZSYT3fYJMhBBvSmJlVWpRfnxRaU5q8SFGU2DATGSWEk3O B8Z3Xkm8oYmhuaWhkbGFhbmRkZI4b8mHK+FCAumJJanZqakFqUUwfUwcnFINjEXaPwTulxTM PDtZ+q/yzqJG/uR4p5Cac+dWvNI0ia3cvqdZ9J6j0G6B87c17278y35l7ftCGYl1Lcym+jeE nuRZrau4tvIyh83G7uf/Liz+9NA9ofKXs0/10XX/5/g+yFdWff2QVeNh59IdvSHRk1+bL7A4 Erb19GP+GenP9r289XL78jzVEzxKLMUZiYZazEXFiQDu82dKtwIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161104102428eucas1p1522816f613cbe1259f406fab7a563782 X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUb?= =?UTF-8?B?7IK87ISx7KCE7J6QG1ByaW5jaXBhbCBFbmdpbmVlciwgU29mdHdhcmU=?= X-Global-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUbU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtQcmluY2lwYWwgRW5naW5lZXIsIFNvZnR3YXJl?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDA1Q0QwNTAwNTg=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161104090140epcas3p38edbc3a363a05ef5302774d01dced04e X-RootMTR: 20161104090140epcas3p38edbc3a363a05ef5302774d01dced04e References: <20161104090009.GA22682@localhost.localdomain> On Fri, 4 Nov 2016 17:00:09 +0800 Han Pingtian wrote: > I think > > $ a='abc def' > $ print ${a:/def} > > will get 'abc ', but it is 'abc def'. So it works just like ${a//#%def}? > The 'entire word' in the document is the same thing of 'entire string'? "Word" isn't a very good word, but I'm not sure what would be better. In this context, what it means is either a complete scalar value, or an element of an array. There is an option to use space-delimited words in substitution, but it's not the default (and I don't think it's all that commonly used as array processing tends to be more useful). Hence % a=(abc def) % print ${a:/def} abc % a=(abc "abc def") % print ${a:/def} abc abc def More widely in the documentation, it's treated as synonymous with a single command line argument. That's what it means in "history word", and I think that's what's inspired the usage here, although it's confused by the many ways of getting words explicitly or implicitly split. If we can find something unambiguous we can change it generally, though it'll need a lot of editing. The best we've got at the moment is this in paramater substitution documentation: If var(name) is an array parameter, and the tt(KSH_ARRAYS) option is not set, then the value of each element of var(name) is substituted, one element per word. Otherwise, the expansion results in one word only; with tt(KSH_ARRAYS), this is the first element of an array. No field splitting is done on the result unless the tt(SH_WORD_SPLIT) option is set. See also the flags tt(=) and tt(s:)var(string)tt(:). We could add something like the following, though it slightly overlaps with what I've just quoted. pws diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index b731516..f465b2f 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -572,6 +572,18 @@ noderef(Modifiers) in noderef(History Expansion) can be applied: for example, tt(${i:s/foo/bar/}) performs string substitution on the expansion of parameter tt($i). +In the following descriptions, `word' refers to a single word +substituted on the command line, not necessarily a space delimited word. +With default options, after the assignments: + +example(array=("first word" "second word") +scalar="only word") + +then tt($array) substitutes two words, `tt(first word)' and `tt(second +word)', and tt($scalar) substitutes a single word `tt(only word)'. This +may be modified by explicit or implicit word-splitting, however. The +full rules are complicated and are noted at the end. + startitem() item(tt(${)var(name)tt(}))( The value, if any, of the parameter var(name) is substituted.