From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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, DKIM_VALID_AU,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 4299D21377 for ; Fri, 15 Nov 2024 11:37:41 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1731667061; b=AjiYZ3JDlIyvOeb4GD71wFAeQ17laesK640LoRm/Iwl7HXAviqLws2oUhpI7Gi0RGoN2awhhMD FOx4QU6HNQmvfi7ZhgOIF8nmU7ThyCln8L1ShKv3T29fED1j3wNxQBFUcGciojIOEiT74hMsw1 wFkIafiWbya8kqkDk0aEu0O70A6Z7YeFBCDWfsytiGEQYLJxkCI/YmnoXmJoMU4Ucpmw1nwuXs cfYQOw9gJ3pdqGvERN/vlrXNqzgBMF74h+QcXsUSNIH44lymKllDsa2vrWqPkoW+hTbyGfhpJb M+s/BNV8eNkMbKLJDzAmt/xZv1v1q75XCF4Epv5xBuBfMQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (csmtpq1-prd-nl1-vmo.edge.unified.services) smtp.remote-ip=84.116.50.35; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1731667061; bh=HPYdJzWjJZgMouUHIBgFlkRva7XDcmEL11Q0klzHI+s=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject: References:In-Reply-To:Message-ID:To:From:Date:DKIM-Signature: DKIM-Signature; b=HwoRlwKWWwuAL9go9kp+4JdbiQ7zfw3faWGQUyFYRpx0/NaI+PlbFeFt1ypQKyGWasoOPRC0Db p8O3pOgLFMtDHYppHMKMm0uVo3PPtipTjP0Ms3OpHcUi3NIY0fXPeKxyToa+W2ZhAkXQ+0Ird+ JEeJuj2zzrWj2qV9WPg7myJjufNi0YyH1NPq1zA02cMnXeJLyJkX4MsqG4bnUHDWbT4E/7/Ewr LFYf48ISfdKCDUciuDnHR5Bsdgbpgky1OunHX8hXU0Te9x4SfZVYcDNU6Xf4C1j73ZIG5wN8QS zHyCWIWmu/nLEDG5Mv4V8TLwQBtI+P+Qhc+K+INzuOouUA==; 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:MIME-Version:Subject:References:In-Reply-To:Message-ID:To:From: Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=+3PHirM/jfiiDT9byJ8W7K3aZnzzv5zA76fs11Dfv7k=; b=d+NDW2L0efo4pv4VXdNUsLXnni lpcJtBnfpwyNW5Vr4elNBMM4PUJzdHizFSgOFLQohHHu1Kc1Rre9b2jM7xDktqsxDZ3T+oAQEacYb iVlKXZ1uVFz6gRP80jP2xgp7DKU4lIKWb1yTPXSDeUcumEBmWp24WJQBzrKEzKr5wfi3XWgmFO5FM PvIaaRd3p+grHMBODYTfP76Smq4tGvLycCFdY0b4g9/n6LQGmUxWPW8nAD9HUfe+TC91OV0vokGW+ NkF95D/Ppf6ebNqnv8e6DgHgEHXWo+teeWPVSPLLEXlTe3o/75oRkFVyOMrE6FQ97t2O5RHnVnEwU KUyJ+ucw==; Received: by zero.zsh.org with local id 1tBtht-00043H-MR; Fri, 15 Nov 2024 10:37:41 +0000 Authentication-Results: zsh.org; iprev=pass (csmtpq1-prd-nl1-vmo.edge.unified.services) smtp.remote-ip=84.116.50.35; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none Received: from csmtpq1-prd-nl1-vmo.edge.unified.services ([84.116.50.35]:41599) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1tBtg3-000394-Iq; Fri, 15 Nov 2024 10:35:48 +0000 Received: from oxsmtp4-prd-nl1-vmo.nl1.unified.services ([100.107.83.44]) by csmtpq1-prd-nl1-vmo.edge.unified.services with esmtp (Exim 4.93) (envelope-from ) id 1tBtg2-000AMQ-Kf for zsh-users@zsh.org; Fri, 15 Nov 2024 11:35:46 +0100 Received: from oxbe14-prd-nl1-vmo.nl1.unified.services ([100.107.83.72]) by oxsmtp4-prd-nl1-vmo.nl1.unified.services with ESMTP id Btg2tX2zuI4hHBtg2tFjgo; Fri, 15 Nov 2024 11:35:46 +0100 X-Env-Mailfrom: p.w.stephenson@ntlworld.com X-Env-Rcptto: zsh-users@zsh.org X-SourceIP: 100.107.83.72 X-CNFS-Analysis: v=2.4 cv=Yd1H5xRf c=1 sm=1 tr=0 ts=67372402 cx=a_exe a=YQry3I751P0aBfd9j3H/qQ==:117 a=OXoQyn4X4dwA:10 a=IkcTkHD0fZMA:10 a=ZkvPBPLQAAAA:8 a=NLZqzBF-AAAA:8 a=pGLkceISAAAA:8 a=W09T_jua7CsSqHWbQgIA:9 a=PRpDppDLrCsA:10 a=QEXdDO2ut3YA:10 a=oZnKP-IzZtsA:10 a=E9U9qXoGi2zwcFWpRlMT:22 a=SFr2u9Cu4sbnRqnMvguH:22 X-Authenticated-Sender: p.w.stephenson@ntlworld.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ntlworld.com; s=meg.feb2017; t=1731666946; bh=HPYdJzWjJZgMouUHIBgFlkRva7XDcmEL11Q0klzHI+s=; h=Date:From:To:In-Reply-To:References:Subject; b=xzwFqO+0YZbqFbJvj6oD4zucKq569hEIeXUofF9xVJ1RjplDvVWyQkU86X1HYM9hq O0JiXelMG2G4ZcHCN/lkjZ+qml/kgapLqI176zev7+oWJcIOC6b6Ithofz1e5FmB/p FXXX0zTGcZWyXk8nU41wdR6MhHm5lF07A+Mf0dtUqX1lkv+oRmZsn1wPbIg370rF7m 9ehq1C/eAiRjngGjKx/LyCK47q9UCtM5ccUqwZb3BLhXV9gMajy1vGUL/EqmW/CKPB lhujrnaJX2cfLbKGd4o+CLQjH4dQGRndTjW283cQx41inRJu+oVmQezEPb6U7A3yj8 yoGpr2LP/dWKg== Date: Fri, 15 Nov 2024 10:35:46 +0000 (GMT) From: Peter Stephenson To: zsh-users@zsh.org Message-ID: <2095757117.3382258.1731666946586@mail.virginmedia.com> In-Reply-To: <1723013458.3381717.1731666592474@mail.virginmedia.com> References: <1723013458.3381717.1731666592474@mail.virginmedia.com> Subject: Re: Testing whether a string matches any pattern from a list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer X-Originating-IP: 147.161.224.189 X-Originating-Client: open-xchange-appsuite X-CMAE-Envelope: MS4xfNch6+sllmnmrzBI+Et9bYa3+faX3zObXn2VJiDNjfkxUhk8XHsIJs/jvxqXqVSA2FP5znauezY/xQti4sIaecvrlyAWNUo6LBKhV3gGETBYiKm80Ti1 KIi5imxeF7ToDyzJxTIbVrUde7LRWnM+grYthEZCBm/OvedHvNUzruDqmheysWHYS9NHmaaAQmdPtdKrK14LxQ5xaogyJe+ysrP1dbVlywNCMybDtU4hgnr+ X-Seq: 30110 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 15/11/2024 10:29 GMT Peter Stephenson wr= ote: > > On 15/11/2024 00:12 GMT Philippe Altherr > > wrote: I have an array that contains a list of patterns and a > > string. I would like to check whether the string matches any of the > > patterns in the array. For example if patterns=3D("foo*" "*bar"), then = a > > test for "foob", "obar", and "foobar" should return true and one for > > "ooba" should return false. > > > > I hoped that I could use the following: > > > > if [[ -v patterns[(k)$string] ]]; then ... fi; > > > > Unfortunately, the pattern matching effect of the=C2=A0subscript flag > > (https://zsh.sourceforge.io/Doc/Release/Parameters.html#Subscript-Flags= )=C2=A0(k) > > only works for associative arrays, not for regular arrays. >=20 > I think you might be hitting a slightly different problem, that the test > is taking place in a special context that doesn't do the pattern lookup. > This is rather obscure so probably not intentional. >=20 > At least, the following does work for me (and doesn't > seem to be dependent on any options I have): >=20 > % string=3DB\* > % print $signals[(k)$string] > BUS >=20 > See if this works: >=20 > local lookup=3D${patterns[(k)$string]} > if [[ -n $lookup ]]; then > # ... > fi Actually, it's only -v that's special --- so you can simply do if [[ -n ${patterns[(k)$string]} ]]; then # ... fi pws