Wildcard-specs

ERCF08 Bob Gray bob at its63b.ed.ac.uk
Fri Oct 10 02:46:12 AEST 1986


In article <4162 at brl-smoke.ARPA> lacasse at RAND-UNIX.arpa writes:
>
>If you have all day, you can use:
>    find . -exec grep string {} \;

You would be faster with
	grep string `find . -print`
provided that there weren't too many filenames. There is a
limit built into your system on the number of parameters you
can pass in an exec().

It has always seemed odd to me that a system with a
hierarchical file system didn't have some pattern which
recursively matched to sub directories and the files in
them. It would be very nice to do something like

	vi **.mk

to edit all the makefiles in a particular set of directories.

In most cases the pattern matching of
e.g.
	ls -l **
has the same meaning as
	ls -l `find . -print`

The problems begin when you attempt to make the "**"
wildcard as general as the other metacharacters. The pattern
"**x**"  means "find any file or directory which has the
letter x in its name. match to either the filename or
to ALL the files in the sub-tree if it is a directory.
i.e.
	**xyz**
should match to
	abcxyz.x
	abc/abcxyz.y
	abc/def/xxyzz/a.c
	abc/def/xxyzz/b.c
	abc/def/xxyzz/d.c
	abc/def/xxyzz/e.c

I started to implement "**" pattern matching in the Bourbe
shell a few years ago. Getting it to match with example 1.
was fairly trivial. The more general "**xyz**" case caused
an explosion in the number of filename matches before
sorting and elimination of duplicates. It was very easy to
run out of space on the machine I was working on in those days.

If I dig the code out of the archives, what sould happen in
a command like
	cp **.c x

where x is a directory. Should the shell quietly make new
directories or should it issue seperate cp commands for each
target directory, then let cp complain if they don't exist.
	Bob Gray.
	ERCC.



More information about the Comp.unix mailing list