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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28201 invoked from network); 17 Nov 2022 09:00:43 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 17 Nov 2022 09:00:43 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1668675643; b=ZIbDItqHGZFqejJdh0uSXFoYGDmM8KvXqsQmfGLXIteyw0gyq1u6ZrvAshZUBIJi7c2QpN/lac pf8BMo3O4Ix4r9xBndWMtQkEbCRYZcnWHLQmlwY/kZQn+0VpSwZbbbwiTfqVOtXSXbRyum3JcB 8MSs/5I1xU2aU6o1gjhyFGAV+9KkB55biSthkvoOiikrlThSPKBE8O2yubPp96LLJERLPooWt/ T/wZs455RDHSP/grr/dj5kJa9z6u7TYydj7Uc+PYqYV+gY0XcY62pP03y0EKdYGoYvjTG5mHv6 QNqwUJQK/58RyxWegGEQaiUQ+FZEjkH0IP0UvTnBJVvdOQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f174.google.com) smtp.remote-ip=209.85.219.174; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1668675643; bh=WuRWuE0wdkifRgbh5D1+Mxl1dpSTM1B5z9/DhJkcnKU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=ECyjAsPNYTRbjkb32AKCyAc39t0Ji7ev99mfzML1z2w//WQh2x03uTMbSCH9MweILMUydSMl9v +d+Sr3SpN6ReOVbg+pTPwYtqkUIK5qHXbia0OcCXx03pX5Ckv+iqwQMJP0I0059yscGaDlvC4D qeZ6/k8dvp06Woov8pwXoJC5FqLzK0XSXIn/0FnfeRxZE7DmqgyX79PvwAupKHCKrF5d8xfweV E4My69CiPpTpKuX1jWVIXwkeXCOgAizVIh40KII3V1QmFPB9B8Ax+jQDKGhDVdXWgyDibEMgDY NHm/ut/s6RmpGqHD1qiIZbvkNEEdWwBh76swPKzccYd+cA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=YrmL41XxHbQpjmI3hq+vKLv14hc2FA4TpFaEobuIBHg=; b=K5jzyGjnFvrRZJGfUmpj2p2C/e /HPSBsaIy5QvYt4zkU55f69pWch9XXusUxpv+lUTR/m0XoZYDnBam9Nnc7VIALhoqyqgM/frnM3JO WG6UFVIVDYNoH5qRqzJ36wVCaZPQFTwbyyl5nPPE06Jc+CEU2EH565LrVgOQ0J7tqVUyZJjr7E6Hq dkQRPLegBTOQKQ0+vSDzxB11eKlCgxoaIHfHpHcINPNZ/x6zvl4sNeWF51L6S6NbwYf2wFtRhflWe JV6h46RsaKz5U518cz6AVjctz3AXIvBTPzCaVMKtqvwQmYU+Z4Wi8001SzqVr9jhtj+NRq8Q8xTTA G9tS68+w==; Received: by zero.zsh.org with local id 1ovalG-0007Cp-TE; Thu, 17 Nov 2022 09:00:42 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f174.google.com) smtp.remote-ip=209.85.219.174; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-yb1-f174.google.com ([209.85.219.174]:37635) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ovakW-0006So-5j; Thu, 17 Nov 2022 08:59:57 +0000 Received: by mail-yb1-f174.google.com with SMTP id 63so1117893ybq.4 for ; Thu, 17 Nov 2022 00:59:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YrmL41XxHbQpjmI3hq+vKLv14hc2FA4TpFaEobuIBHg=; b=T8fufOQrb2eBfK4fD9hPQ2tvu3nH1jKPWI1gE0tpW7+M/YUKi0sEV3XzSLHPwbShhs 86prp3QKAJntiQUeT0jZs9tB9CBlMDo2c1J3ZqPJLx04vH2QnnQUeRrFUm/xq4sVKQol 7P/zVflegQiJj/MlJtA5xf2WtGbHWpm94XdTIet8SZMkPEt5uN3M0Dlc8Kz2TJlrX/U2 uuCGM8RSiwEy+O3OSuku8SZ3mF9Tm4tAiH/kIN86QmCMScemGWNE1ETtWekbEqZydXJw 6qiT0X0QSE5qmvHua448vqfOif9vYM74GFfXG2uxw+bKDU3IW3fniTvvC4PVmNMIaw99 Zd+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YrmL41XxHbQpjmI3hq+vKLv14hc2FA4TpFaEobuIBHg=; b=4qVw0gawS68iqelvDsYYx8lA66sCxdLjomPr+2t5JEoOBgUGIGnUFbm8/bxRMLKkw9 mbnz3ilDmSZSvojKpV0uC1AHrFj1cRX34RS44NBA0l6lYT6SKucOYptPRElVu5Y89nd/ RrEfSuPqqYDq3iLlsMV6FqLtYYolktrb9/ZwJzneKWW24EpIIyV40F1uuvDvnvrHc5GM Z26w9Sxz0iUTEXYrlb34bKh6QzjZSoCm7sc7+vYvLSLcWejtjguvCWGERK7LnoRY6h53 IRfX6JNCPDW5FBakDbf56MlwQKYWw7b8uVP0VqoXZ+WZBN2Dr4f011lIT5ler95k7p/n 2GxQ== X-Gm-Message-State: ANoB5pl7VEpjjnjgPv700VFEWCQd8IMPkn7a2zEn6TJfowmuF9fP0ZAa M0zugRt/qUQ2J+YO1GNkKUE+AUAisFzxb1eUqfs= X-Google-Smtp-Source: AA0mqf5TwXSbuktMt3z/k+/ZmOvAdd7FpSdF0VHpa8knazTM6UfQziDO4FejCRI67gkE85YK+nBEYOlbiCglGNVdKKk= X-Received: by 2002:a25:8189:0:b0:6ca:6bfb:3374 with SMTP id p9-20020a258189000000b006ca6bfb3374mr1279116ybk.175.1668675594854; Thu, 17 Nov 2022 00:59:54 -0800 (PST) MIME-Version: 1.0 References: <34a949c4-0853-4c65-d2ad-db40749dff81@eastlink.ca> <2dd50dc8-cdbc-02e0-0e1e-485718732d0d@eastlink.ca> <3a10f310-3ee8-d3b4-f6db-7fdb18b81b1f@eastlink.ca> <77692192-70b3-8a6a-fd01-d5f8b37f59b2@eastlink.ca> <879a8fb0-74b7-5250-d2ff-2f60585f48a4@eastlink.ca> <0ce205d5-31f9-907a-61bd-1bf5acb37f0f@eastlink.ca> <1d79745a-10fd-3a23-c67f-af1048be6b19@eastlink.ca> In-Reply-To: From: Roman Perepelitsa Date: Thu, 17 Nov 2022 09:59:40 +0100 Message-ID: Subject: Re: Belaboring substitution syntax To: Bart Schaefer Cc: Ray Andrews , zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" X-Seq: 28407 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: On Thu, Nov 17, 2022 at 3:32 AM Bart Schaefer wrote: > > On Wed, Nov 16, 2022 at 6:15 AM Roman Perepelitsa > wrote: > > > > On Wed, Nov 16, 2022 at 3:09 PM Ray Andrews wrote: > > > > > > "${array[@]}" ... Read: protect the elements of this array, do any expansions within them, but do NOT combine them ?? > > > > No, this just expands the array to all its elements. > > In the base cases, you can think of it as "if I can't see it, nothing > happens to it." The exceptions only occur when you start adding > parameter flags like ${(e)array[@]}. If I didn't know that ${array[@]} without quotes does not in general expand to the array's elements, I could be confused by this exchange, so I'll post some examples for Ray's benefit. This does nothing (the array's content is unchanged): array=("${array[@]}") This may change the content of the array: array=(${array[@]}) The content of the array is changed by this statement in two ways: 1. All empty elements are removed. 2. If sh_word_split is set, elements of the array are split on $IFS. To demonstrate (1): % () { emulate -L zsh local array=('' 'foo bar') typeset -p array array=(${array[@]}) typeset -p array } typeset -a array=( '' 'foo bar' ) typeset -a array=( 'foo bar' ) To demonstrate (2): % () { emulate -L zsh -o sh_word_split local array=('' 'foo bar') typeset -a array=( 'foo bar' ) array=(${array[@]}) typeset -p array } typeset -a array=( '' 'foo bar' ) typeset -a array=( foo bar ) In short, "${array[@]}" expands to array elements just like "$scalar" expands to the scalar's value. Versions without quotes are more complex, for they may transform the value in various ways. Additionally, unless ksh_arrays is set (it's unset by default), these two are equivalent: "${array[@]}" "${(@)array}" And these four are equivalent: ${array[@]} ${(@)array} ${array} $array Roman.