[comp.unix.questions] Empty Directory?

gandalf@csli.STANFORD.EDU (Juergen Wagner) (04/29/88)

	set nonomatch
	if ( ! -e $dir/* ) echo $dir is empty.

-- 
Juergen "Gandalf" Wagner,		   gandalf@csli.stanford.edu
Center for the Study of Language and Information (CSLI), Stanford CA

rbj@icst-cmr.arpa (Root Boy Jim) (05/04/88)

   From: Juergen Wagner <gandalf@csli.stanford.edu>
   Date: 28 Apr 88 22:29:13 GMT

	   set nonomatch
	   if ( ! -e $dir/* ) echo $dir is empty.

Didn't work under 4.3 BSD. How about a two-step solution?

	ls -A $dir > /tmp/$$
	if ( -z /tmp/$$ ) echo directory empty

Csh needs a few other operators, such as a test for symbolic links.

   Juergen "Gandalf" Wagner,		   gandalf@csli.stanford.edu
   Center for the Study of Language and Information (CSLI), Stanford CA

	(Root Boy) Jim Cottrell	<rbj@icst-cmr.arpa>
	National Bureau of Standards
	Flamer's Hotline: (301) 975-5688
	The opinions expressed are solely my own
	and do not reflect NBS policy or agreement
	I represent a sardine!!

mdorion@cmtl01.UUCP (Mario Dorion) (05/08/88)

In article <13241@brl-adm.ARPA>, rbj@icst-cmr.arpa (Root Boy Jim) writes:
> 	   set nonomatch
> 	   if ( ! -e $dir/* ) echo $dir is empty.
> 
> Didn't work under 4.3 BSD. How about a two-step solution?
> 
> 	ls -A $dir > /tmp/$$
> 	if ( -z /tmp/$$ ) echo directory empty

Wouldn't
        if [ `ls -a $dir | wc -w` -eq 2 ]  \* for . and .. *\
        then echo $dir is empty
        fi
work ?????

BTW: what does "set nonomatch" do ???

-- 
     Mario Dorion              | ...!{rutgers,uunet,ihnp4}!     
     Frisco Bay Industries     |            philabs!micomvax!cmtl01!mdorion
     Montreal, Canada          |
     1 (514) 738-7300          | I thought this planet was in public domain!

morrell@hpsal2.HP.COM (Michael Morrell) (05/12/88)

/ hpsal2:comp.unix.questions / mdorion@cmtl01.UUCP (Mario Dorion) /  7:15 pm  May  7, 1988 /

BTW: what does "set nonomatch" do ???

-- 
     Mario Dorion              | ...!{rutgers,uunet,ihnp4}!     
     Frisco Bay Industries     |            philabs!micomvax!cmtl01!mdorion
     Montreal, Canada          |
     1 (514) 738-7300          | I thought this planet was in public domain!
----------

In csh, setting "nonomatch" causes the shell to leave unchanged a construct
like "*" which does not match anything, rather than giving an error message.
For example, if my current directory only has the file "foo" and I type:

  ls b*

I will normally get an error ("No match").  If nonomatch is set, however,
the shell will say: "b* not found".

  Michael Morrell

rbj@icst-cmr.arpa (Root Boy Jim) (05/18/88)

   From: Mario Dorion <mdorion@cmtl01.uucp>

   In article <13241@brl-adm.ARPA>, rbj@icst-cmr.arpa (Root Boy Jim) writes:
   > 	   set nonomatch
   > 	   if ( ! -e $dir/* ) echo $dir is empty.
   > 
   > Didn't work under 4.3 BSD. How about a two-step solution?
   > 
   > 	ls -A $dir > /tmp/$$
   > 	if ( -z /tmp/$$ ) echo directory empty

   Wouldn't
	   if [ `ls -a $dir | wc -w` -eq 2 ]  \* for . and .. *\
	   then echo $dir is empty
	   fi
   work ?????

I suppose.

   BTW: what does "set nonomatch" do ???

I assume you must be running TPC UNIX, or you would have read the csh manual.
Anyway, "mkdir x; cd x; set nonomatch; echo qaz*" echo's 'qaz*'. The
variable `nonomatch' allows the echo to succeed instead of producing an
error. Personally, I dislike both the name and the implementation. I would
have called the variable `nullmatch' and returned the empty string.

Now for some head scratching, what does `unset nonomatch' mean? :-)

	Mario Dorion              | ...!{rutgers,uunet,ihnp4}!     
	Frisco Bay Industries     |            philabs!micomvax!cmtl01!mdorion
	Montreal, Canada          |
	1 (514) 738-7300          | I thought this planet was in public domain!

	(Root Boy) Jim Cottrell	<rbj@icst-cmr.arpa>
	National Bureau of Standards
	Flamer's Hotline: (301) 975-5688
	The opinions expressed are solely my own
	and do not reflect NBS policy or agreement
	My name is in /usr/dict/words. Is yours?