From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12744 invoked by alias); 7 Nov 2016 02:30:21 -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: 22098 Received: (qmail 24082 invoked from network); 7 Nov 2016 02:30:21 -0000 X-Qmail-Scanner-Diagnostics: from mx0a-001b2d01.pphosted.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(148.163.156.1):SA:0(0.0/5.0):. Processed in 0.502274 secs); 07 Nov 2016 02:30:21 -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=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: hanpt@linux.vnet.ibm.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at linux.vnet.ibm.com does not designate permitted sender hosts) Date: Mon, 7 Nov 2016 10:30:01 +0800 From: Han Pingtian To: zsh-users@zsh.org Subject: Re: What's the 'word' in parameter relpacement expansion? Mail-Followup-To: zsh-users@zsh.org References: <20161104090009.GA22682@localhost.localdomain> <20161104102425.5df2b0c6@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161104102425.5df2b0c6@pwslap01u.europe.root.pri> User-Agent: Mutt/1.7.1 (2016-10-04) X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16110702-0016-0000-0000-0000051808DB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006035; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000189; SDB=6.00777509; UDB=6.00374329; IPR=6.00554806; BA=6.00004857; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013221; XFM=3.00000011; UTC=2016-11-07 02:30:10 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16110702-0017-0000-0000-000034682C43 Message-Id: <20161107023001.GA13317@localhost.localdomain> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-11-07_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611070046 On Fri, Nov 04, 2016 at 10:24:25AM +0000, Peter Stephenson wrote: > 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. Thanks. So ':/' is the same thing of '/#%'? It looks like a kind of redundance.