zsh-users
 help / color / mirror / code / Atom feed
* destructuring assignment
@ 2014-02-03 17:36 Roman Neuhauser
  2014-02-03 18:00 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Roman Neuhauser @ 2014-02-03 17:36 UTC (permalink / raw)
  To: zsh-users

hello,

having an array such as

  declare -a partitions; partitions=(
    /boot:boot:512:fat:boot,legacy_boot
    :swap:10240:swap
    /:root:-:btrfs
  )

i'd love to iterate it like:

  for mountp name size fs flags in ...; do
    # 1st iteration
    # $mountp=/boot $name=boot $size=512 fs=fat flags=boot,legacy_boot
    # 2nd iteration
    # $mountp= $name=swap $size=10240 fs=swap flags=
    # 3rd iteration
    # $mountp=/ $name=root $size=- fs=btrfs flags=
  done

i tried for ... in "${(@s.:.)partitions}", but that seems to join the
array before applying the (s.:.), which is contrary to my expectations,
but i may be misreading the manual (14.3.1: "[(@)] is distinct from
*field splitting* by the `f`, `s` or `z` flags, which still applies
within each array element.")

this is what i see:

  roman@stick ~ 1026:0 > echo $ZSH_VERSION
  5.0.2
  roman@stick ~ 1027:0 > typeset -p foos
  typeset -a foos
  foos=(a1:a2:a3a,a3b,a3c b1:b2:b3 :c2:c3)
  roman@stick ~ 1028:0 > for a b c in "${(@s.:.)foos}"; do typeset -p a b c; done
  typeset a=a1
  typeset b=a2
  typeset c='a3a,a3b,a3c b1'
  typeset a=b2
  typeset b='b3 '
  typeset c=c2
  typeset a=c3
  typeset b=''
  typeset c=''

and this is what i want:

  roman@stick ~ 1028:0 > for a b c in "${(???)foos}"; do typeset -p a b c; done
  typeset a=a1
  typeset b=a2
  typeset c=a3a,a3b,a3c
  typeset a=b1
  typeset b=b2
  typeset c=b3
  typeset a=''
  typeset b=c2
  typeset c=c3

-- 
roman


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

end of thread, other threads:[~2014-02-04  4:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-03 17:36 destructuring assignment Roman Neuhauser
2014-02-03 18:00 ` Peter Stephenson
2014-02-03 22:08   ` Bart Schaefer
2014-02-04  2:53     ` setopt histignorespace not working Ray Andrews
2014-02-04  3:34       ` Ray Andrews

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).