* What's the 'word' in parameter relpacement expansion? @ 2016-11-04 9:00 ` Han Pingtian 2016-11-04 10:24 ` Peter Stephenson 0 siblings, 1 reply; 4+ messages in thread From: Han Pingtian @ 2016-11-04 9:00 UTC (permalink / raw) To: zsh-user Hi, 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'? In zshexpn: ... or `#%' in which case the pat‐ tern must match the entire string. The first `/' may be preceded by a `:', in which case the match will only succeed if it matches the entire word Thanks in advance! ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What's the 'word' in parameter relpacement expansion? 2016-11-04 9:00 ` What's the 'word' in parameter relpacement expansion? Han Pingtian @ 2016-11-04 10:24 ` Peter Stephenson 2016-11-07 2:30 ` Han Pingtian 0 siblings, 1 reply; 4+ messages in thread From: Peter Stephenson @ 2016-11-04 10:24 UTC (permalink / raw) To: zsh-user On Fri, 4 Nov 2016 17:00:09 +0800 Han Pingtian <hanpt@linux.vnet.ibm.com> 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. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What's the 'word' in parameter relpacement expansion? 2016-11-04 10:24 ` Peter Stephenson @ 2016-11-07 2:30 ` Han Pingtian 2016-11-07 3:20 ` Bart Schaefer 0 siblings, 1 reply; 4+ messages in thread From: Han Pingtian @ 2016-11-07 2:30 UTC (permalink / raw) To: zsh-users On Fri, Nov 04, 2016 at 10:24:25AM +0000, Peter Stephenson wrote: > On Fri, 4 Nov 2016 17:00:09 +0800 > Han Pingtian <hanpt@linux.vnet.ibm.com> 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. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What's the 'word' in parameter relpacement expansion? 2016-11-07 2:30 ` Han Pingtian @ 2016-11-07 3:20 ` Bart Schaefer 0 siblings, 0 replies; 4+ messages in thread From: Bart Schaefer @ 2016-11-07 3:20 UTC (permalink / raw) To: zsh-users On Nov 7, 10:30am, Han Pingtian wrote: } } Thanks. So ':/' is the same thing of '/#%'? It looks like a kind of } redundance. Yes, these are very similar. One form was invented by zsh, the other was imported from another shell for compatibility. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-11-07 3:19 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CGME20161104090140epcas3p38edbc3a363a05ef5302774d01dced04e@epcas3p3.samsung.com> 2016-11-04 9:00 ` What's the 'word' in parameter relpacement expansion? Han Pingtian 2016-11-04 10:24 ` Peter Stephenson 2016-11-07 2:30 ` Han Pingtian 2016-11-07 3:20 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).