* Odd expansion behavior @ 2014-07-03 7:43 Dima Kogan 2014-07-03 9:12 ` Peter Stephenson 0 siblings, 1 reply; 3+ messages in thread From: Dima Kogan @ 2014-07-03 7:43 UTC (permalink / raw) To: zsh-workers Hi. I'm observing something odd. It might be a bug, but I don't understand it well-enough to call it that. I see this: $ x=(1 2 3); echo xxx${^x} xxx1 xxx2 xxx3 This output makes sense. However something slightly different is strange: $ x=(1 2 3); y=xxx${^x}; echo $y xxx1 2 3 Here the ${^x} form turns on the RC_EXPAND_PARAM option, and it's apparently not kicking in in the second (broken) case. Even if I setopt it, I still don't have this working. I asked on #zsh and osse helpfully pointed out that this can be made to work by expressing the assignment as 'y=(xxx${^x})' instead, which does work. But shouldn't it work the other way as well? osse wasn't sure why the original form wasn't working, so I'm reporting it here as a maybe-bug. Thanks dima ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Odd expansion behavior 2014-07-03 7:43 Odd expansion behavior Dima Kogan @ 2014-07-03 9:12 ` Peter Stephenson 2014-07-03 12:28 ` Peter Stephenson 0 siblings, 1 reply; 3+ messages in thread From: Peter Stephenson @ 2014-07-03 9:12 UTC (permalink / raw) To: Dima Kogan, zsh-workers On Thu, 03 Jul 2014 00:43:23 -0700 Dima Kogan <dima@secretsauce.net> wrote: > I'm observing something odd. It might be a bug, but I don't understand > it well-enough to call it that. > > I see this: > > $ x=(1 2 3); echo xxx${^x} > xxx1 xxx2 xxx3 > > This output makes sense. However something slightly different is strange: > > $ x=(1 2 3); y=xxx${^x}; echo $y > xxx1 2 3 > > I asked on #zsh and osse helpfully pointed out that this can be made to > work by expressing the assignment as 'y=(xxx${^x})' instead, which does > work. That's the difference between a scalar and an array assignment. In a scalar assignment, arrays are forced immediately to scalars, i.e. single strings joined (by default) with spaces. So the $x gets turned immediately into "1 2 3"; the "^" has no special effect because you're just joining that string with the "xxx". It's a little bit like (but not exactly the same as) putting double quotes around the expression. It might throw a little bit of extra light on this if you look at the words that are coming out; you can do this with "print -l" which outputs one word per line. So in the first case and after array assignment you get xxx1 xxx2 xxx3 because you are getting three different words from ${^x}, each one joined to xxx, while after the scalar expansion you get xxx1 2 3 because you have a single word. pws ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Odd expansion behavior 2014-07-03 9:12 ` Peter Stephenson @ 2014-07-03 12:28 ` Peter Stephenson 0 siblings, 0 replies; 3+ messages in thread From: Peter Stephenson @ 2014-07-03 12:28 UTC (permalink / raw) To: zsh-workers On Thu, 03 Jul 2014 10:12:01 +0100 Peter Stephenson <p.stephenson@samsung.com> wrote: > That's the difference between a scalar and an array assignment. The doc is somewhat scattered. This might help a bit. diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index 719f06a..77f0098 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -19,7 +19,11 @@ cindex(simple commands) cindex(commands, simple) A em(simple command) is a sequence of optional parameter assignments followed by blank-separated words, -with optional redirections interspersed. +with optional redirections interspersed. For a description +of assignment, see the beginning of +ifnzman(noderef(Parameters))\ +ifzman(zmanref(zshparam)). + The first word is the command to be executed, and the remaining words, if any, are arguments to the command. If a command name is given, the parameter assignments modify diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 5bccdc2..dbac511 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -21,14 +21,20 @@ indent(var(name)tt(=)var(value)) If the integer attribute, tt(-i), is set for var(name), the var(value) is subject to arithmetic evaluation. Furthermore, by replacing `tt(=)' -with `tt(+=)', a parameter can be added or appended to. See +with `tt(+=)', a parameter can be added or appended to. + +In scalar assignment, var(value) is expanded as a single string, in +which the elements of arrays are joined together; filename expansion is +not performed unless the option tt(GLOB_ASSIGN) is set. See noderef(Array Parameters) for additional forms of assignment. To refer to the value of a parameter, write `tt($)var(name)' or `tt(${)var(name)tt(})'. See ifzman(em(Parameter Expansion) in zmanref(zshexpn))\ ifnzman(noderef(Parameter Expansion)) -for complete details. +for complete details. This section also explains the effect +of the difference between scalar and array assignment on parameter +expansion. In the parameter lists that follow, the mark `<S>' indicates that the parameter is special. pws ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-07-03 12:39 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-07-03 7:43 Odd expansion behavior Dima Kogan 2014-07-03 9:12 ` Peter Stephenson 2014-07-03 12:28 ` Peter Stephenson
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).