How do I tell when a directory is empty in a script?
Rob McMahon
cudcv at warwick.ac.uk
Fri Apr 5 23:52:07 AEST 1991
I know this is getting silly, but
In article <572 at bria> uunet!bria!mike writes:
>True enough; I didn't account for hidden files. Okay, then how about this
>instead?
>
> if [ `ls $dir/* $dir/.[!.]* | wc -l` = 0 ] ; then
touch ..hidden
Oops. Also not all versions of sh have the [!...] construction.
I think the only sensible way to do this is [ `ls -a $dir | wc -l` = 2 ]; that
should be pretty portable.
>And under systems that do have this behaviour, I have seen them list . and ..
>along with everything else.
You sure ? The ls's I've seen that change behaviour for root list everything
but . and .., a la -A.
Cheers,
Rob
--
UUCP: ...!mcsun!ukc!warwick!cudcv PHONE: +44 203 523037
JANET: cudcv at uk.ac.warwick INET: cudcv at warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England
More information about the Comp.unix.questions
mailing list