Empty Directory? (Was: Picking a character from a word)
Root Boy Jim
rbj at icst-cmr.arpa
Wed May 18 03:21:21 AEST 1988
From: Mario Dorion <mdorion at cmtl01.uucp>
In article <13241 at brl-adm.ARPA>, rbj at 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 at 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?
More information about the Comp.unix.questions
mailing list