From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4621 invoked from network); 3 Nov 2004 22:49:53 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 3 Nov 2004 22:49:53 -0000 Received: (qmail 7534 invoked from network); 3 Nov 2004 22:49:46 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Nov 2004 22:49:46 -0000 Received: (qmail 24846 invoked by alias); 3 Nov 2004 22:48:56 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8156 Received: (qmail 24832 invoked from network); 3 Nov 2004 22:48:55 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 3 Nov 2004 22:48:55 -0000 Received: (qmail 6197 invoked from network); 3 Nov 2004 22:47:56 -0000 Received: from pop-a065d10.pas.sa.earthlink.net (207.217.121.251) by a.mx.sunsite.dk with SMTP; 3 Nov 2004 22:47:54 -0000 Received: from cpe-24-221-169-78.ca.sprintbbd.net ([24.221.169.78] helo=ckhb.org) by pop-a065d10.pas.sa.earthlink.net with esmtp (Exim 3.33 #1) id 1CPTuy-00066B-00 for zsh-users@sunsite.dk; Wed, 03 Nov 2004 14:47:52 -0800 From: "S. Cowles" Reply-To: scowles@earthlink.net Organization: personal To: zsh-users@sunsite.dk Subject: how to show all parms matching a given substring? Date: Wed, 3 Nov 2004 14:47:46 -0800 User-Agent: KMail/1.5.1 MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Description: clearsigned data Content-Disposition: inline Message-Id: <200411031447.50010.scowles@earthlink.net> X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: ** X-Spam-Status: No, hits=2.6 required=6.0 tests=OPT_IN_CAPS autolearn=no version=2.63 X-Spam-Hits: 2.6 I would like to solicit suggestions from others about a better, simpler way= to=20 get all parameters in the current context matching a given substring. If=20 this can be done using parameter expansion patterns, so much the better. =46or right now, I use the following function. Thanks, scowles at earthlink dot net showparms(){ # find all parms with name or value matching a given fixed substring. availopts=3Dhv usage=3D"usage: $0 -{${availopts}}" usage=3D$(printf "%s\n\t%s\n" $usage "h help") usage=3D$(printf "%s\n\t%s\n" $usage "v include parm values") v=3D"" while getopts ":${availopts}" opt do case ${opt} in v ) v=3D"v" ;; h ) echo "${usage}" >&2 return ;; \? ) echo "invalid option usage." >&2 echo ${OPTIND} >&2 echo "${usage}" >&2 return ;; \: ) echo "missing option." >&2 echo ${OPTIND} >&2 echo "${usage}" >&2 return ;; esac done shift $(( ${OPTIND} - 1 )) [[ -z "$1" ]] && { echo "must provide a pattern." >&2 return } spatt=3D"$1" [[ -z "${v}" ]] && { # work on parameter names, only. eval " showparm () { set + | while read line do [[ -z \"\${line}\" ]] && { continue ; } [[ \${line[(i)${spatt}]} -le \${#line} ]] && { echo \${line} ; } done } " } [[ -n "${v}" ]] && { # work on parameter names and values. eval " showparm () { set | while read line do [[ -z \"\${line}\" ]] && { continue ; } [[ \${line[(i)${spatt}]} -le \${#line} && \${line[(i)=3D]} -le \${#line} ]] && { echo \${line} ; } done } " } showparm }