zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-user <zsh-users@zsh.org>
Subject: Re: What's the 'word' in parameter relpacement expansion?
Date: Fri, 04 Nov 2016 10:24:25 +0000	[thread overview]
Message-ID: <20161104102425.5df2b0c6@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20161104090009.GA22682@localhost.localdomain>

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.


  reply	other threads:[~2016-11-04 10:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161104090140epcas3p38edbc3a363a05ef5302774d01dced04e@epcas3p3.samsung.com>
2016-11-04  9:00 ` Han Pingtian
2016-11-04 10:24   ` Peter Stephenson [this message]
2016-11-07  2:30     ` Han Pingtian
2016-11-07  3:20       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161104102425.5df2b0c6@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).