From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay1.UU.NET ([137.39.1.5]) by archone.tamu.edu with SMTP id <18921>; Fri, 31 Jan 1992 15:12:54 -0600 Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay1.UU.NET with SMTP (5.61/UUNET-internet-primary) id AA04225; Fri, 31 Jan 92 16:12:37 -0500 Received: from srg.UUCP by uunet.uu.net with UUCP/RMAIL (queueing-rmail) id 161111.10046; Fri, 31 Jan 1992 16:11:11 EST Received: from ceres.srg.af.mil by srg.srg.af.mil id aa28925; Fri, 31 Jan 92 16:01:14 EST From: culliton@srg.af.mil (Tom Culliton x2278) X-Mailer: SCO System V Mail (version 3.2) To: rc@archone.tamu.edu Subject: Match operator puzzlement Date: Fri, 31 Jan 1992 15:01:15 -0600 Message-Id: <9201311601.aa02527@ceres.srg.af.mil> Reply-To: srg!culliton@uunet.uu.net OK maybe it's just 'cuz it's Friday but my poor brain refuses to come up with a good answer to this one. While writing some fairly large and complex rc scripts I had a requirement to match something against a list of patterns specified at the command line and figured it'd be easy give rc's ~ match operator. The first attempt was something like this: patterns=`{echo $1} # go from '*.o *.a' to (*.o *.a) # lots of stuffto generate a list on file names.... for (i in $list) { if (~ $i $patterns) { dealwith $i } else { handle $i } } Which didn't work as planned for semi-obvious reasons involving re-scanning. This didn't distress me too much because I mostly understood why after a bit of thought. The next most obvious thing to try was somthing like this patterns=$1 # we don't care if it's a list for this # lots of stuff to generate a list on file names.... for (i in $list) { if (eval ~ $i $patterns) { # etc... OOPS! I encountered a file name with a $ in it so make that if (eval ~ '$i' $patterns) { # etc... But what about patterns with $ and so forth in them? If we make $patterns a list again and say '$patterns' to protect against that, we get literal matching. I haven't been able to find a way out of the swamp here any words of wisdom would be appreciated. Thanks for listening. Tom