From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=DKIM_ADSP_ALL, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RDNS_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: (qmail 10867 invoked from network); 19 Mar 2020 04:38:58 -0000 Received-SPF: pass (primenet.com.au: domain of zsh.org designates 203.24.36.2 as permitted sender) receiver=inbox.vuxu.org; client-ip=203.24.36.2 envelope-from= Received: from unknown (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTP; 19 Mar 2020 04:38:58 -0000 Received: (qmail 1248 invoked by alias); 19 Mar 2020 04:38:47 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45579 Received: (qmail 4554 invoked by uid 1010); 19 Mar 2020 04:38:47 -0000 X-Qmail-Scanner-Diagnostics: from mx.spodhuis.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25751. spamassassin: 3.4.2. Clear:RC:0(94.142.241.89):SA:0(-4.3/5.0):. Processed in 1.828349 secs); 19 Mar 2020 04:38:47 -0000 X-Envelope-From: zsh-workers+phil.pennock@spodhuis.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at spodhuis.org designates 94.142.241.89 as permitted sender) Date: Thu, 19 Mar 2020 00:38:02 -0400 From: Phil Pennock To: Lawrence =?utf-8?Q?Vel=C3=A1zquez?= Cc: scowles@ckhb.org, zsh-workers@zsh.org Subject: Re: using dynamic patterns on the left hand side of case statement clauses Message-ID: <20200319043802.GA27914@fullerene> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: OpenPGP: url=https://www.security.spodhuis.org/PGP/keys/keys-2013rsa-2020cv25519.asc On 2020-03-18 at 21:29 -0400, Lawrence Velázquez wrote: > Search the zshexpn(1) man page for "${~spec}" for a more thorough > explanation, but the '~' basically turns GLOB_SUBST on for just > that parameter expansion. Good stuff, but I'll offer up one refinement: you can turn on GLOB_SUBST just for the joining pattern, without turning it on for the entire pattern. % a=('a*' beta gamma delta) % c=('alpha', 'a*' 'apple') % for d in $c; do case $d in ${(j:|:)~a} ) echo "match in a for ${(q-)d}" ;; *) echo "no match for ${(q-)d}" ;; esac; done match in a for alpha, match in a for 'a*' match in a for apple % for d in $c; do case $d in ${(~j:|:)a} ) echo "match in a for ${(q-)d}" ;; *) echo "no match for ${(q-)d}" ;; esac; done no match for alpha, match in a for 'a*' no match for apple You can thank Peter Stephenson for adding the support for that, when I was asking about implementing set manipulation for arbitrary content using zsh auto-unique arrays, some years ago now. -Phil