From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay2.UU.NET ([137.39.1.7]) by archone.tamu.edu with SMTP id <45329>; Mon, 3 Feb 1992 08:49:41 -0600 Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP (5.61/UUNET-internet-primary) id AA03740; Mon, 3 Feb 92 09:49:27 -0500 Received: from srg.UUCP by uunet.uu.net with UUCP/RMAIL (queueing-rmail) id 094521.239; Mon, 3 Feb 1992 09:45:21 EST Received: from ceres.srg.af.mil by srg.srg.af.mil id aa13484; Mon, 3 Feb 92 9:22:06 EST From: culliton@srg.af.mil (Tom Culliton x2278) X-Mailer: SCO System V Mail (version 3.2) To: rc@archone.tamu.edu Subject: Re: Match operator puzzlement Date: Sun, 2 Feb 1992 14:20:38 -0600 Message-Id: <9202021520.aa00569@ceres.srg.af.mil> Reply-To: srg!culliton@uunet.uu.net John Mackin writes: > The reason a straightforward attempt doesn't work isn't really anything > to do with rescanning at all, since there IS no rescanning I thought about adding "or lack thereof", honest I did! But since it seemed to imply that not rescanning was wrong it got left out. The real difficulty, which I saw quite clearly, is that ~ doesn't accept a list of patterns (primarily so you can match the empty list) so the eval is needed to flatten the command out and rescan it (flattening the list doesn't work because it becomes a single item) but at this point we get undesired rescanning (in a filename context?) which is not easily quoted away. There also seems to be a minor ambiguity between string matching contexts and filename expansion contexts. In most contexts $ gives the contents of variable (or something related) and patterns (using * ? []) give a list of filenames. In matching contexts $ works the same but patterns are compared against strings. Where the two collide it gets a bit messy. Given: patterns=('*.o' '*.a') # or patterns='*.o *.a' eval ~ '$i' $patterns It's not clear to me which context *.o will be evaluated in. Will it filename expand to a whole list of patterns which are then matched? This matters for obvious reasons. Maybe Byron can clarify this? For the curious the application is to scan a development directory tree automatically generating a makefile/target for configuration management purposes. One of the requirements was to be able to exclude files matching a certain template or set of templates (given on the command line) from the target, typically things like *.o *.a and other generated or binary files. While testing it I actually did encounter a filename with a $ in it (a backup or temporary file for some app) 8-P and while I don't like names like that, my program can't just choke on them! My less than satisfactory solution was to carefully document that the patterns had to be quoted, just so, when they are given on the command line. Byron's sed script seems like it will solve most of the problem and John's newline hack should cover any remaining glitches. Tom