From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5428 invoked from network); 31 May 2021 20:05:34 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 31 May 2021 20:05:34 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1622491534; b=wHBDJviNYo06lBvKdDBbJo+k5RlBKcEk26OQIUuOtW7kY49+SplszMj+7NmPWD+kOWK3jW7JvQ hErxI9DjLKEYtZklV265qTn2BOxH5pJZtQiXOskdBV3UasPMae02n5u6K0BaaghiOQYkIUVg9v R8u1XmY21UI7H08//eGz0UmNu/mYRS4UCeoIeNI+IQC8yLbMm6YJi9M8eWgeyCyEltrnZSN2be +J+sbMGoBUML70owQ3s72Ix2CkjnwkLCZ3O9ArbIEgb7q94fGpJxef6i6JHfWumdC+FxK31Oi0 m5VJ4XI+iZWV3KgVUZunbpjIoCrriGvezxfTxmQLPxoJow==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (wael.necoro.dev) smtp.remote-ip=92.60.36.208; dmarc=none header.from=necoro.eu; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1622491534; bh=PuSSnEZURnX7hg2p3MfPO2eV9nWvk1m1K2XCW8Vtst8=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:To:Subject:DKIM-Signature; b=kmqD198oI6Y+KGKeXzedLmvfz9tPip8qX7u8Jrgqgkqdzl5Fvl3kthoNzizdkHT38A66j7LxW4 WeGsG/VLHmg5xziVXxheKLmG/IVUx3BGdiWNm5BsaFUr+jqcSUUnSofTbj4gORZm7UnBwFyHpB ltRZxtOzyE4/lh3wmUCd3AyTb7p/NHRB/KlVBCJLS9dZujNX3Kx7NOcJYh5VaPlol+fJMmDaE3 ttyvElgGkcfgaVM+ZckBg3OR2nI7SMhkR1PFKf1m9qmJnOSY9edWhYkpkuXzFnSgY5QvYKnQ79 mgjlQMdXp6vgZiQ6VtlHEKtm70Cm5gKsqBtwPSL4DqpKSg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:To: Subject:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=BVB6DdHFOmjRsw4nb2oWZS8UfZOSmFxEiRUVPxT0Bro=; b=EFp50qbDgJW5dYNzhbeMAtzkjB UyPznWqE4V8P4zVxYIn/YnUwXxsM9xwdfhcx3bsE8XkzS8RlE/uMyVQqsItlLK/wo0M/jFWRPZcKU VzN18qPi6SW/7+bMYN2qjiJ2F2S4TEM2M27T44p1f8bwX25ST5JfbLf1A1d080cw1dVKUbvlWty6f t4mo5966F5VrFWh4a0EDJR0txxpGRl9z+DWcYasjIg3GHT/JTwCT1g5M4vzK10O3xWdJOBFQaKpJ+ MsCjAbp3Nk+vGaAmJyLhys0bi1GWI6jSxMH6uiChq+4W8ifPZaTf/JQjmzo7yIinpyRs6KFwM4Sbl k/kdn5zg==; Received: from authenticated user by zero.zsh.org with local id 1lnoAH-0000TO-OW; Mon, 31 May 2021 20:05:33 +0000 Authentication-Results: zsh.org; iprev=pass (wael.necoro.dev) smtp.remote-ip=92.60.36.208; dmarc=none header.from=necoro.eu; arc=none Received: from wael.necoro.dev ([92.60.36.208]:37816) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lno9V-000PhJ-C6; Mon, 31 May 2021 20:04:45 +0000 Received: from wael.necoro.dev (localhost [IPv6:::1]) by wael.necoro.dev (Postfix) with ESMTP id 06FB4E1F57 for ; Mon, 31 May 2021 22:04:44 +0200 (CEST) Received: from [192.168.0.38] ([31.17.213.74]) by wael.necoro.dev with ESMTPSA id mnsJOlxBtWBiGhUAc/PHBg (envelope-from ) for ; Mon, 31 May 2021 22:04:44 +0200 Subject: Re: [Review Request] Arrays and their usage To: zsh-users@zsh.org References: <26fc6ecd-4a05-e562-7274-ba045df536bf@necoro.eu> <20210531173651.2pfklkhv5zizfldg@chazelas.org> From: =?UTF-8?Q?Ren=c3=a9_Neumann?= Message-ID: <1eb8dc21-eb40-cc32-4ca8-c049d7273a03@necoro.eu> Date: Mon, 31 May 2021 22:04:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <20210531173651.2pfklkhv5zizfldg@chazelas.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Seq: 26754 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: > Here's my take on answering this (repeating some of what has > already been said). Greatly appreciated! > First, I'd say: `...` form of command substitution should really > be banned these days. That's really a broken heritage from the > Bourne shell. There's not good reason to keep using it these > days. The main problem with it is the handling of backslash > inside it (and the awkward nesting and the fact that it's less > legible, etc...). Fun fact: I prefer `...`, because I find it more legible, especially in the x=`cmd y z` form¹. But TIL, that `` and $() are not interchangable. Up to now, I thought the one is syntactic sugar for the other. > The sed command could be written: > > sed -n 's/pkgname = //p' Good catch, thanks > Then, leaving `...` (or the better $(...)) unquoted performs > IFS-splitting, so you're left with the same kind of conundrum as > you get in POSIX shells when you leave any form of expansion > ($param, $((arith)) as well there!) unquoted though at least > zsh doesn't perform globbing there: > > [...] > > pkgs=( > ${(f)"$( > makepkg --printsrcinfo | > sed -n 's/pkgname = //p' > )"} > ) Thank you for this detailed explanation. Not relying on IFS seems a good thing to do, although the rest of the script probably does here and there². Also thanks for this example of code structuring. /me likes. (NB though: The linebreak for the two pipe elements was inserted for this email only, with me hoping, that backslash newline was the correct thing to do ;)) > The more idiomatic zsh variant to that ksh syntax would be: > > pkgs=( $DATABASE/$^pkgs ) > > (same as rc's pkgs = ( $DATABASE/$pkgs )). What does 'rc' stand for? Again, thanks for this effort! - René ¹ Longer story: $() is easily confused with ${}. Also, `...` is more "in the background" and I let my highlighting make it clear to me, that I'm in a subcommand. I would always prefer $() in large complex expressions though, because. ² Although one could argue that setting IFS to something else than $'\n' WILL break a lot of stuff, so one can expect it to be sane.