zsh-workers
 help / color / mirror / code / Atom feed
* $^=var and leading/trailing blanks
@ 2016-10-08 15:12 Stephane Chazelas
  2016-10-11  3:18 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Stephane Chazelas @ 2016-10-08 15:12 UTC (permalink / raw)
  To: Zsh hackers list

$ a='  a b '
$ print -l +$^=a
+
+a
+b
+
$ print -l "${(@)^=a}"

a
b

$ print -l +${^${=a}}
+a
+b

Why the extra first and last element the the first two commands?

-- 
Stephane


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: $^=var and leading/trailing blanks
  2016-10-08 15:12 $^=var and leading/trailing blanks Stephane Chazelas
@ 2016-10-11  3:18 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2016-10-11  3:18 UTC (permalink / raw)
  To: Zsh hackers list

On Sat, Oct 8, 2016 at 8:12 AM, Stephane Chazelas
<stephane.chazelas@gmail.com> wrote:
>
> Why the extra first and last element the the first two commands?

This is sort of explained under the s:: expansion flag:

     For historical reasons, the usual behaviour that empty array
     elements are retained inside double quotes is disabled for arrays
     generated by splitting; hence the following:

          line="one::three"
          print -l "${(s.:.)line}"

     produces two lines of output for one and three and elides the
     empty field.  To override this behaviour, supply the "(@)" flag as
     well, i.e.  "${(@s.:.)line}".

When you add the rcexpandparam flag, you get "the usual behavior" back
again (otherwise an array of only empty elements would behave like an
empty array and discard everything).  When you  nest the expansions,
the inner split gets the empty elements removed when it expands, and
then rcexpandparam applies to the remaining elements of that result.

You don't get two elements for the two leading spaces because
shwordsplit behaves that way.  If you use (s: :) instead, then you do
get one empty element for each space.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-11  4:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-08 15:12 $^=var and leading/trailing blanks Stephane Chazelas
2016-10-11  3:18 ` 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).