zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: destructuring assignment
Date: Mon, 3 Feb 2014 14:08:56 -0800	[thread overview]
Message-ID: <CAH+w=7bx31TcdThDyQvOKjHO8x+58dyU-hoJec2eBs-RoGMXMg@mail.gmail.com> (raw)
In-Reply-To: <20140203180049.775877d9@pwslap01u.europe.root.pri>

[-- Attachment #1: Type: text/plain, Size: 1213 bytes --]

On Mon, Feb 3, 2014 at 10:00 AM, Peter Stephenson
<p.stephenson@samsung.com>wrote:

> On Mon, 03 Feb 2014 18:36:00 +0100
> Roman Neuhauser <neuhauser@sigpipe.cz> wrote:
> > having an array such as
> >
> >   declare -a partitions; partitions=(
> >     /boot:boot:512:fat:boot,legacy_boot
> >     :swap:10240:swap
> >     /:root:-:btrfs
> >   )
>

If you were to put a trailing colon on the partitions with no mount flags,
you'd have the same number of colons in each array element, which might
make some other things easier (as PWS mentioned).

>   for mountp name size fs flags in ...; do
>

Given the trailing colons to create empty flags fields for the lines that
do not have flags, you can do

    for mountp name size fs flags in "${(@s.:.)${(j.:.)partitions}}"

However, I'd still prefer Peter's nested loops.


> for line in $partitions; do
>   for mountp name size fs flags in "${(@s.:.)line}"; do
>     print mountp=$mountp name=$name size=$size fs=$fs flags=$flags
>   done
> done
>

Another option is

while IFS=: read mountp name size fs flags; do
  # ...
done <<<${(F)partitions}

That should work even without the trailing colons, but could be tricky if
you need standard input inside the loop body.

  reply	other threads:[~2014-02-03 22:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-03 17:36 Roman Neuhauser
2014-02-03 18:00 ` Peter Stephenson
2014-02-03 22:08   ` Bart Schaefer [this message]
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='CAH+w=7bx31TcdThDyQvOKjHO8x+58dyU-hoJec2eBs-RoGMXMg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --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).