Testing for non-empty wildcards

Paul Fox fox at marlow.uucp
Sun Dec 4 05:27:21 AEST 1988


Hello wide world...yet another boring shell question.

Given that in the C-shell you can do things like:

	if ( -e ...long..file..spec ) ...

is there a way to test whether a sub-directory contains any
wild-carded files. What I mean is, I have a subdirectory 'sccs'
in each of my development directories. I have a shell script 'sccs'
in /usr/local/bin which does some nice but useful things with the
sccs commands. I can do something like:

	sccs update

which translates into:

	foreach i (sccs/p.*)
		set file = something_horrible
		delta sccs/s.$file
		get sccs/s.$file
	end

The problem I have is that if there are no sccs/p.* files, then
cshell complains that there is a wildcard mismatch.

My current hack is the following:

                set nonomatch
                set a = sccs/p.*
                if ( "$a" == "sccs/p.*" ) exit 0

which relies on the fact that if nonomatch is set, then '*' evaluates
to '*' if the wildcard fails. I think this is horrible, and may have
nasty side effects.

How does one do this properly in the C-shell & Bourne Shell.
(I am not particularly interested in the K-sh since I need portability.
Yes I know C-shell is not available on all systems, but it is 
available on more systems that K-sh).

Many thanks


=====================
     //        o      All opinions are my own.
   (O)        ( )     The powers that be ...
  /    \_____( )
 o  \         |
    /\____\__/        Tel: +44 628 891313 x. 212
  _/_/   _/_/         UUCP:     fox at marlow.uucp



More information about the Comp.unix.wizards mailing list