From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4543 invoked by alias); 3 Feb 2014 18:11:15 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18381 Received: (qmail 9774 invoked from network); 3 Feb 2014 18:10:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f4-b7f796d000005a13-07-52efd953295d Date: Mon, 03 Feb 2014 18:00:49 +0000 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: destructuring assignment Message-id: <20140203180049.775877d9@pwslap01u.europe.root.pri> In-reply-to: <20140203173600.GG14992@isis.sigpipe.cz> References: <20140203173600.GG14992@isis.sigpipe.cz> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplluLIzCtJLcpLzFFi42I5/e/4Fd3gm++DDE595LLYcXIlowOjx6qD H5gCGKO4bFJSczLLUov07RK4Mi7techasJG3YuuCiSwNjP84uxg5OSQETCTuHXvKBGGLSVy4 t56ti5GLQ0hgKaPEi9s7WKAcJomZC+ewglSxCKhK3P7bxw5iswkYSkzdNJsRxBYREJVYvmIz WFwYqObDh0VsIDavgL3Etd8PmUFsTgFTiU+zJ4HVCAFtXvz6HVicX0Bf4urfT1BX2EvMvHKG EaJXUOLH5HssIDazgJbE5m1NrBC2vMTmNW+ZJzAKzEJSNgtJ2SwkZQsYmVcxiqaWJhcUJ6Xn GuoVJ+YWl+al6yXn525ihAThlx2Mi49ZHWIU4GBU4uF9uP9dkBBrYllxZe4hRgkOZiUR3mPn 3wcJ8aYkVlalFuXHF5XmpBYfYmTi4JRqYCzsFmPYNLvzzeOEb7YRYb/5mcJzd3pe3JOX07Vv mXf9qkOOW2NOKWfPkplolrD5sMxtS0vly0acLpc5so2C71TzfBS+06A4cePGg/9kb2duyD8R dse1c1Xb4rfTNkTwqhq71D+7ntjx3F1Ds3rfml3vX7ksDSxiiLxz/8tFTp+K+wnn7Ep6Tiux FGckGmoxFxUnAgAe3PhZIAIAAA== On Mon, 03 Feb 2014 18:36:00 +0100 Roman Neuhauser wrote: > 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.:.) It's all rather hairy and you've run up against ol' rule 10. 10. Forced joining If the `(j)' flag is present, or no `(j)' flag is present but the string is to be split as given by rule 11., and joining did not take place at step 5., any words in the value are joined together using the given string or the first character of $IFS if none. Note that the `(F)' flag implicitly supplies a string for joining in this manner. Anyway, as you've written it above, you've still got the problem that you've got variable numbers of colons in the line, and unless you can think of some way of padding the invididual entries in the array (which may be possible but won't be nice) a single loop won't handle that. You'd need two 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 That does seem to work. pws