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 718F62E80C for ; Fri, 15 Nov 2024 11:30:53 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1731666653; b=AKIlLwnsfuA2FWiJgCUGrBBJpxF1Xkmop4EDHwqH9ibSY5P7iYT+dHUX8jVBQbGLd3bHrHseoe P4RKEvMdbgUXhFCitJITi+JhOQe/R7z5algLHRxH73TOAVxya/RHXqhQgBPLFu2t0sBeIa28V9 a9WvTl+19R6NS8R8bid1wPdOx5IMVq7GvsbCrWGXuXfPO9dbaIFUnfxeK7TkuYzAzgosTDUmtM 7zm0A5Y+xyWWeuLy2O51YROWA74jEFI8g5ws9BhX6kglKjXO5RCJr0y3w/+ik7epMMA0dPKy1R V7/7n6zQw9Kv2dp5AZhu/ZpXe54mD2yidibOXVzSE/IZqw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (csmtpq4-prd-nl1-vmo.edge.unified.services) smtp.remote-ip=84.116.50.41; 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=1731666653; bh=DWPziqYJ6wmwVRYC+7d9xBLkP86O+sYiPTZ9CM7pE+o=; 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=roY4uLKRt+PXSRN+r+pTHP/Ty+9DbOZ7Zp+y4AQueD8DkXABLVwXRycHUTJUrpwJa2XZh0dChh LZ8nWMq/lbtm+YLlxHMHcFbBfSMCJuDa6ZJ1K4pGgjmdfQvDuhsf+EEsFXczRj3yTtXcJ+CjlF cpdM58t05qlmfR9lmfxHDwMFJJIPNWCizw2+UZ60cMC90TNOb0QhoMRoduFq0US0Jvk+3psvxj mRKtV76cq7Icmxboe43H3Pv8PYJcx5JP9X2QmGtz86aUo6FVDWODPy6FO+VIjLuDO7AKW4IIrm Y6wbmM7AFVRIIIgzggl6u/y9pxgvIHmMIrtUxooCBeTeWw==; 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=N+WLbfCqVsolBldpUpUjX4CbRs4wfnty+gEoAy1lRuI=; b=VR0Qt16zOQk9oRLladZqruF6ci LpKuZWryGPjdmMcJkf/ttzhw2+4WRC6JeleGOMdJ1MrRn6FyLD6jamh27phO1ZNBc2x3hurA5n/8d MoY+n7rg0LVeqOm8aZMx5IepY32khZ+3xh4xHpKiEOtK1KNI+oJrUvBMJoe2CU9cbLsEKva8Isqub ZmF4JrwpNtQNJzTCOh70hPSGw01kP+GnrNF7jHmz2bavcSKNFyPK0OH5L6VQtBkfSc/BH6eySj7vk l+HzahWNWBSdftgTUXbC6fvI9blmu8EYNmlbawr4bImXYRNM//GI6X5qWZsIQqwFp3QPj/sl3pANv 6fZBIbXQ==; Received: by zero.zsh.org with local id 1tBtbI-0002fO-N9; Fri, 15 Nov 2024 10:30:52 +0000 Authentication-Results: zsh.org; iprev=pass (csmtpq4-prd-nl1-vmo.edge.unified.services) smtp.remote-ip=84.116.50.41; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none Received: from csmtpq4-prd-nl1-vmo.edge.unified.services ([84.116.50.41]:23731) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1tBtaL-0001x5-LM; Fri, 15 Nov 2024 10:29:54 +0000 Received: from oxsmtp2-prd-nl1-vmo.nl1.unified.services ([100.107.83.137]) by csmtpq4-prd-nl1-vmo.edge.unified.services with esmtp (Exim 4.93) (envelope-from ) id 1tBtaK-006xho-H3 for zsh-users@zsh.org; Fri, 15 Nov 2024 11:29:52 +0100 Received: from oxbe14-prd-nl1-vmo.nl1.unified.services ([100.107.83.72]) by oxsmtp2-prd-nl1-vmo.nl1.unified.services with ESMTP id BtaKtG9lky1UjBtaKt2eub; Fri, 15 Nov 2024 11:29:52 +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=Gre4+l1C c=1 sm=1 tr=0 ts=673722a0 cx=a_exe a=YQry3I751P0aBfd9j3H/qQ==:117 a=OXoQyn4X4dwA:10 a=IkcTkHD0fZMA:10 a=ZkvPBPLQAAAA:8 a=pGLkceISAAAA:8 a=TElrdWGMTkBJdjfwlCEA: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=1731666592; bh=DWPziqYJ6wmwVRYC+7d9xBLkP86O+sYiPTZ9CM7pE+o=; h=Date:From:To:In-Reply-To:References:Subject; b=ykunH5Pvrua1x9R1DWZjvzLWMVa6GDuVtiZ0GGz7kLo1HVFwitJ2g2wVtcAvpoVCg cUFjX1Z/FFNMnoSIxga5epo1D6jBXFin+wfnwo1kDLJzPE3PuesHrFRRPlKyfbr8dT +lakH6WTtaVk86/Z8noDBEBEUaJzoCVnScgKQ5r9cAbI4FM28JbnBQMcZk8SsdPPzN vdS5Iy8qam3/gE7opK8xPj0DXZgkEx9FLvGxqPA5KIrkGkDklL7rG+8zNAYx7TmqyU mn0g2gFGZr3Mqs20oeQJVyOs0T0c4vIemdQFW3lzSyZQMKd+oqU+yQZZ6vdYrueL6/ Z0W4qwDpLtWcQ== Date: Fri, 15 Nov 2024 10:29:52 +0000 (GMT) From: Peter Stephenson To: zsh-users@zsh.org Message-ID: <1723013458.3381717.1731666592474@mail.virginmedia.com> In-Reply-To: References: 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: MS4xfFXZhdwdJykOlb42mH8O76ycdYS8piaQzj0oznB/5PIReW5QwcpmRehAXlE1z4JkgHJwfnemFNRv+9lEeDEK+/mqwdlHQ6WMgeK2r/mTIWJugBVhznlC LguBxsE+rH0BeqULmN/y7oN6z9C5wsgETY4W7ZVaiXzCK6KP0vS/crC1rRMy3bRLdEd25reGI2FnvnbqIhLG/9l4wC6f4nj/IPnMR7KBvAhilYGqdE/9w1e4 X-Seq: 30109 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 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. 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. At least, the following does work for me (and doesn't seem to be dependent on any options I have): % string=3DB\* % print $signals[(k)$string] BUS See if this works: local lookup=3D${patterns[(k)$string]} if [[ -n $lookup ]]; then # ... fi pws