[comp.unix.wizards] Testing for non-empty wildcards

fox@marlow.uucp (Paul Fox) (12/04/88)

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@marlow.uucp

shankar@hpclscu.HP.COM (Shankar Unni) (12/06/88)

> 	foreach i (sccs/p.*)
> 		set file = something_horrible
> 		delta sccs/s.$file
> 		get sccs/s.$file
> 	end
  ....
> 
>                 set nonomatch
>                 set a = sccs/p.*
>                 if ( "$a" == "sccs/p.*" ) exit 0
> 

Try something a little nicer (if a little more cpu-expensive):

    find sccs -name 'p.*' -exec something_or_other

or

    find sccs -name 'p.*' -print | while read file
	do
	    # list of commands on $file
	done

(/bin/sh or /bin/ksh example)

---
Shankar.

chip@ateng.ateng.com (Chip Salzenberg) (12/26/88)

According to shankar@hpclscu.HP.COM (Shankar Unni):
>
>    find sccs -name 'p.*' -print | while read file
>	do
>	    # list of commands on $file
>	done

Or:

    them="`find SCCS -name "p.*" -print | sed 's#^SCCS/p\.##`"
    if [ ! "$them" ]
    then
	echo "Nothing is checked out!"
    else
	for f in $them
	do
	    get -s -p SCCS/s.$f | diff - $f
	done
    fi

This has the nice feature of collecting all the names into a variable for
examination and possible re-use.
-- 
Chip Salzenberg             <chip@ateng.com> or <uunet!ateng!chip>
A T Engineering             Me?  Speak for my company?  Surely you jest!
	  "It's no good.  They're tapping the lines."