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 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 11918 invoked from network); 10 Jan 2024 00:22:29 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Jan 2024 00:22:29 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1704846149; b=ZMX/UQPoWjrYTv+H3V0AD9WlhWeND9uXr2k9KUGgKRHAK7bpDJmewdpx529tselhV1Zn+eO9Oq TvbMfo89wpR/WOIOfXCsFkCXPVAhGwYAHSB1tV57FUQeqEHjHQUDDkF62bOvV028AomC/o64in eo1U8Ir72PpCSbJ2x4BAJ4L9F6QJ4PD7+s49jLbkRIE7oyq8NsRv1zkRmjZMBub4jl+xWf/Gz4 GCdD1DH+GGk1NUvzw4O+US3tAYqm/vQW6aMh+YD0fSqXIfTvNXupui/56LCj2wc5yh0NcnXKLW 5Eoob1K0/Szin6QPO2JxxaZbhxgRDpXPA0//kgObQgtUcg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wr1-f50.google.com) smtp.remote-ip=209.85.221.50; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 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=1704846149; bh=8BVIXU6vKDExab0o8ha8v2gt9p2gNb/8OwXlprz4dV0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=pCv+x4n9iyKMPIISUCiCGUzhRgX3XTk71t+bkay7VC2YGJvWtOmS0gywAEDXnek5tIXsTUVkBD Zou91gows743tEHlvfENrjaj9W1UPmDhDkqEsl0ZErsD44PhMKJJ4CBmBfxa4PnCMyTKE5ew2j IM9pYbbIlBMHPBEhcMh5XWwDYG+6HAz7vu05gfp5UAwjDYyrarmYQVxLYy/OOOZyN4edZqaQky nIyfpOx8nodSvCk8Py2vcnDBM4spI4wBvEzkHTcjuy6luaAk2kIsteymO8UyDiROkidLVqh6Gn UP1So6JYUGw7LVCFrhql0DbSUbOG8q+tYafLfsYlLHpEug==; 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-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=xfsKCDSm5RyDKouE/MQNzdOHisaQ1pm0FjzStOp+NuM=; b=rt4jYPkR8FLp4zCDlbBKbASNlV 4/VZrC8tn2qTvEogCDSY3la4m6fD1ToTJ/ygk86zy26aD54UMuLrrzmiQY8afVBqG4f6ZwLGvOIQ/ YdfcyZecP+N1ZlF3p3mkGZLy56i50mR85evWuSOPrM53e/XC37Y9paWj1w17eZZOLS8jyaY0B7Lw/ OueEqt/0u/R8+ALyI43VoAAuKxVPoy8HC8/sUsmJse7YJEyUVYwABmX7stQ+wte0KJQYPRuifQEHR lIkSeyyNE1gSujWU2yV/Q/PEsZViufSo+mr8lk11tvaepUIMceSC/A9hd69JzI8mskeMEdOtoi1fr IXHpzipw==; Received: by zero.zsh.org with local id 1rNMMV-0000en-8M; Wed, 10 Jan 2024 00:22:27 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wr1-f50.google.com) smtp.remote-ip=209.85.221.50; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-wr1-f50.google.com ([209.85.221.50]:45196) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rNMLn-000Pyb-6x; Wed, 10 Jan 2024 00:21:44 +0000 Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-336897b6bd6so3581874f8f.2 for ; Tue, 09 Jan 2024 16:21:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1704846102; x=1705450902; darn=zsh.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xfsKCDSm5RyDKouE/MQNzdOHisaQ1pm0FjzStOp+NuM=; b=jxWHkI/P4H2N5LKikq4e6lVcMI19YLsym4mTAW4gBgQ182NvMRcXpBqPSFJfR5hrIh g15WiSoMftUsCBtJmXI9mSUq0wiu9WuK5e3eiTJfydiYetmkTK1RJZYsJmWBlTmFBZHi jokZj0gVva++O6dkxXHgG/0PPBdubxlk3ihNaMHKGO2mOrQxW94CWUoRNDVV3inxRC2S yoSezJ1Gx+dXeE7Ovso8NA8pMq6wRVpWGKsIh1o04n12+b/buhlFhhuVxfHJwb5139jF A4Lg8B3HO9QqXJbArYf/QBlZICAjtB/M0taFeVtz3QBYs66XFBDLv/bIv6jJmKifolxj XzUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704846102; x=1705450902; h=content-transfer-encoding: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=xfsKCDSm5RyDKouE/MQNzdOHisaQ1pm0FjzStOp+NuM=; b=HOccG7s+IGGUuU6MrhRYf3JjjBaugrWgJg/stQLY6KK9XkMx/RFOHHhL9cIaIS1MxN NpaIv91/TE6lQNV4DqBDcG8++GCNwNlT2fJWz5EJJbXiSzbK9K+NHKuZKUrmTVjFoi6M 3fAkwGaQ+NOA5St00xWh//AYH0iTpUiGwyIJ4FR45q5/jRINQ5AB32ljbfeQmMXjxn3T 6ukM65bZGj8HPy7g5QkEIjCp9URd/TkgvlJyHhyoEJBM6GFoWess+WWydlCFDtnUVGIv 5aSQGDs8U4RGqkNar4i4LA+HYEvBfUjf9eF4SlDJhP66urXuk77t+5P7E6xb8Lweopos VVdg== X-Gm-Message-State: AOJu0YxMss4KuRqOFiE2Lnd+wLNhSqmbhiDWb+MFPcaSWD0+f5HrdpWa TCg/Dw+um8QWMAptvkBECtsxJtVDg4oNgNlztWL7yZZ5HRrS X-Google-Smtp-Source: AGHT+IHu+ZMi9q+1v5WNBp/dJmS0HSk6mKn+heey8cTDtjGVEknHVcffP6GnEsJbCrRUN7A6VOjxX5MX2hirlRrvIio= X-Received: by 2002:a05:600c:705:b0:40e:4252:ff35 with SMTP id i5-20020a05600c070500b0040e4252ff35mr59333wmn.243.1704846102546; Tue, 09 Jan 2024 16:21:42 -0800 (PST) MIME-Version: 1.0 References: <41f9b4d6-8f4a-4220-a86a-b7ccf690bd89@eastlink.ca> In-Reply-To: <41f9b4d6-8f4a-4220-a86a-b7ccf690bd89@eastlink.ca> From: Bart Schaefer Date: Tue, 9 Jan 2024 16:21:31 -0800 Message-ID: Subject: Re: proxy name for array To: Ray Andrews Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 29437 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 Tue, Jan 9, 2024 at 11:00=E2=80=AFAM Ray Andrews wrote: > > typeset -A body=3D() > LIST=3D( one two three four five ) > body[array]=3DLIST > proxy=3D$body[array] # But name of array could change. This whole business with body[array] seems irrelevant to the question, because by the end $proxy is just the name of the array and $body no longer enters into it. If that's not true you're going to have to explain yourself better. > echo $proxy > # Comical efforts included for a laugh ... but you see what I'm trying to= do: You're encountering two issues: #1 - the (P) flag only works on identifiers (not array references) and only for one level of indirection #2 - assignments don't indirect on the identifier to the left The way to do this without an eval is to make a new identifier for (P) to munch on, and then use the syntax that embeds an assignment in a parameter expansion to get the indirection: proxy_assign=3D"${proxy}[2]" : ${(P)proxy_assign::=3DTWO} > eval "${proxy}[2]=3DTWO" # ... and having finally nailed it, it's int= uitive and obvious why this works and the monstrosities above do not :-( > > ... But Bart always cautions against it, so I'm wondering if there's a m= ore kosher way. The problem with that particular construct is that you're eval-ing TWO as well as eval-ing ${proxy}[2], which though harmless in this example could bite you later. Necessary quoting to account for that might not be any simpler than using the extra parameter. The perpetually-delayed next release will include "named references" which change above issue #2 ... typeset -n proxy=3DLIST proxy[2]=3DTWO # Now $LIST[2] is TWO