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,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12285 invoked from network); 2 Jul 2022 18:15:10 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 2 Jul 2022 18:15:10 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1656785710; b=EhW9olju1pKwjDDQAMQLMftZQMVyNrrZnij+iTX2VB0dHU0/b0P4udbJjr0pRT+GaN3IhDK5U/ xGEKQITe3Go6YUhPDtTVfwL4Ex876zWuXyvA1PpRNXH9ygP5fObil4GGU5rVAiyNVfqdnvlBv2 rjkpv4ZrncKmOGKbFGi9t1iiLQbzDCfE0D4qhmGXAH9OYH2hr4bZ6b+QhseyLxjbdGtbkHhoa1 qlva2r0SqsZknMeHcZ9kbsj3YVm/JUjrKxK4eWO3wgs3/sYo7Ygj6eSun/HSFQzm6bf82U67nk +kevBaQlfpLWFLqiZz+D2YT8JPjruh5t/U/P4FF+d08yxg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f41.google.com) smtp.remote-ip=209.85.218.41; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1656785710; bh=9eFVPQhJVDnS3FGpJs3YucFFDQPTHP6pOk5lJgzydyQ=; 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=STwSC7KZtMsGY8N/Sj8BsMlHfN2kf9q7GmzpGZF3Z+qAS5j3CVWlLdaVX2M6EDhhCQWwzUEn9l ZqsiYCSc5b3pdKaBjQqScO4AjxCBzFdJ3g4I/lr89cI5Il29C0Nq/si/asYvw37CEqmz62Lm0m A1jpG6FTvtJzJKvlnAEksTGUl31FuxwlDah7LOwJGbc2Qi/1WCJFDmgk3WkhtQ2c14r4HJ6Ae7 2TZFZ9QiTQZaH0jHbYzvYpzv+NhiyuF5KdQSv4xI9DL7lUCuu6ijTDcb3XBQDElGYUwy0m4wAe AlT50xY3fQtzWNmyaoLXXSG6Bfi7AefExLx/KhSFkaNr7w==; 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=+4ISfZ8/SBVvbIoKXZ4RxDtZt/ScJp11A+lcEln/96o=; b=ZEJ4M7x2y11oMSD7XIRvcsjN2q WekG+k/mtppk8PW0D7kJGBSIhV2btyJ4+MRIJRyUMKSHMEl2ID1HpJgcljIJ1Q0osaZ3nWAJrt1hQ APTxShynaLyAqeKCY0+knTo5MpbwRE53ff81hT+2ermsbHACJ3oSzE9ZW+ZCVX7XiwRVkBFmDN7qP 85rPlMXRTYVndQKOBuec3/a5F+3IiLoSsgGJt2gB8QOAlpuxsExro5qa4LSU9h15Heoo40PPWQDcT KucQJp85HqZBbOJxmALiRZLORLAy7cdVhd302RAkVSAXOsXyaya/wb9ZBnrnhq9Rb8Dth5QoglOFP FxJPN8aw==; Received: from authenticated user by zero.zsh.org with local id 1o7he8-000Kfb-MK; Sat, 02 Jul 2022 18:15:08 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f41.google.com) smtp.remote-ip=209.85.218.41; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f41.google.com ([209.85.218.41]:34552) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1o7hdC-000JyM-2i; Sat, 02 Jul 2022 18:14:11 +0000 Received: by mail-ej1-f41.google.com with SMTP id d2so9552914ejy.1 for ; Sat, 02 Jul 2022 11:14:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+4ISfZ8/SBVvbIoKXZ4RxDtZt/ScJp11A+lcEln/96o=; b=d3UGSQJ2tNIRdJdu+WeDkkVLkAr5qQYMAwKnztkUw5yHFslxMU/CgygiIOJNzgRy+Y /qhr8b9tVFH5DcRBNJOM/xFLxgHk7FS8nQ8pd8QQnloBwZrqIK21bQQ8HXxgx/FT/qV5 x9HaXEnaIpUx3G/N0BuLhb4M2bn0RGsBgvOyaWGBX+zyYYNjIx21KH1v9Ip8EgbU+jkU pHLfyO5B/VxwVVaT0Ir3X4iphByES6O5UayG8E9MIdGJB3xNC8x9Suxqsj/W+HMvE6GF osrPGScXE3KWLwV64thhIMlYA8H2u4Mkemp8MLs3JH7LH00T3muy88C5pXg+Zi/ClHZG GI9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+4ISfZ8/SBVvbIoKXZ4RxDtZt/ScJp11A+lcEln/96o=; b=WpV5vZSAxHQPWTGfsi0E4bzcHzUhbdiSd6eAIRHWNzxVbR9LdtB8p/+/fTUdwjQ+8J D7oyizZFN4u0hvJA8qA7siXwT+BGUcPMEwld7xwAy+NZRVY8sM2bnWwEly38DAtTjJZO O3zkMLHM5E9mgIM7z55by5o+lXjJU8D65a6shbLaLPUqE7UTQs3J2TiItZPcExAxuewm 26BKia5/7ah00UXA1WPW0Gc2oxt5/lL81BXrfYlJv2+MJ9f7jgAGd+rUHNmjEQQBcH4D cScDJ8aWO2GUf3X3roZo2bmPDaaqO3iu46imMutTbb4pWThFdiaYFxGfQoyESSkrWbsw rsZw== X-Gm-Message-State: AJIora9aIWUQcsrjFViEuUSAba3oqEWwvLG+0haDtRiz7yjySWtBVoGg bqGuynu7mCceLijCh0CAEQW9cWq4eiewTYGYLwqc8Q== X-Google-Smtp-Source: AGRyM1vJcC8OKKkWMMJhO4kt3KUQdJ+WDCsnxdYs7yxYiH4h781V5f4lnJuUOZkej0JR/5GKtkRKfE5lHiHC+lyR9Fs= X-Received: by 2002:a17:907:7627:b0:72a:9098:e4d3 with SMTP id jy7-20020a170907762700b0072a9098e4d3mr7862095ejc.389.1656785649228; Sat, 02 Jul 2022 11:14:09 -0700 (PDT) MIME-Version: 1.0 References: <11ca04c9-1503-4cd2-a44b-635dc53e43a8@www.fastmail.com> In-Reply-To: <11ca04c9-1503-4cd2-a44b-635dc53e43a8@www.fastmail.com> From: Bart Schaefer Date: Sat, 2 Jul 2022 11:13:57 -0700 Message-ID: Subject: Re: indirect array element assignment? To: Anthony Heading Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 27860 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 Sat, Jul 2, 2022 at 3:34 AM Anthony Heading wrote: > > What's the best zsh way of doing an indirect array element assignment? fruits=("apple" "banana" "carrot") v=fruits typeset "${v}[3]"=cherry There really isn't a good solution if you're trying to do array slices, i.e., a parenthesized list on the right of the "=". > Everything in zsh I've tried around ${${(P)v}[2]::=cherry} with misc different bracketing gets "not an identifier", suggesting maybe the ::= form doesn't support subscripting. It's not that it doesn't support subscripting, it's that it doesn't support parameter expansions of any kind on the left: % echo ${${grape}::=raisin} zsh: not an identifier: I'm not sure why the error isn't more specific. The syntax, if it worked, would be ${(P)v[3]::=cherry}, because ${(AP)=v::=apple banana carrot} works, but although ${(P)v} gets you a reference to $fruits, as soon as you subscript it as ${(P)v[x]} you end up assigning to a copy of the x'th field of $fruits instead, because zsh doesn't create indirect references to array elements, it substitutes them by value. You can do it this way: z="${v}[3]" echo ${(P)z::=cherry}