zsh-users
 help / color / mirror / code / Atom feed
From: Anssi Saari <as@sci.fi>
To: zsh-users@zsh.org
Subject: Re: Confused about splitting
Date: Sun, 31 Mar 2019 20:56:03 +0300	[thread overview]
Message-ID: <vg3bm1q2ivi.fsf@coffee.modeemi.fi> (raw)
In-Reply-To: <20190331125813.pd45aqx4bvdjnrgr@tarpaulin.shahaf.local2>

Daniel Shahaf <d.s@daniel.shahaf.name> writes:

> «${=g}» does split the value of the parameter 'g'; you can see that with
> «printf '[%s]' ${=g}».  Then, that intermediate result — an array of words — is
> assigned to the parameter 'first' scalarly, so the value of $first is set to be
> the words of the array joined by spaces as a single string.  That's why «echo
> $first» has the right output.  The «echo $#first» line prints the length of the
> string "$first" in characters, because that's what the «$#foo» syntax does when
> foo is a scalar.

This mistaken idea came from the fact $first[1] is just e with
foofunc3. $first[2] is n, $first[3] is o and so on. For some reason I
thought scalars don't have that but they do.

> The fix is to add back the parentheses to make the assignment an array
> assignment: «first=( ${=g} )».

Thanks.


  reply	other threads:[~2019-04-01  9:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-31  9:06 Anssi Saari
2019-03-31 12:58 ` Daniel Shahaf
2019-03-31 17:56   ` Anssi Saari [this message]
2019-03-31 13:12 ` Daniel Shahaf
2019-04-01  9:07   ` Anssi Saari

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=vg3bm1q2ivi.fsf@coffee.modeemi.fi \
    --to=as@sci.fi \
    --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).