From: Roman Neuhauser <neuhauser@sigpipe.cz>
To: zsh-users@zsh.org
Subject: destructuring assignment
Date: Mon, 3 Feb 2014 18:36:00 +0100 [thread overview]
Message-ID: <20140203173600.GG14992@isis.sigpipe.cz> (raw)
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
next reply other threads:[~2014-02-03 17:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-03 17:36 Roman Neuhauser [this message]
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
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=20140203173600.GG14992@isis.sigpipe.cz \
--to=neuhauser@sigpipe.cz \
--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).