Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!nucsrl!tellab5!laidbak!obdient!homer!root From: root@homer.UUCP (Marc Brumlik) Newsgroups: comp.unix.questions Subject: Re: How do I tell when a directory is empty in a script? Message-ID: <900@homer.UUCP> Date: 11 Apr 91 17:28:56 GMT References: <1991Mar30.040400.13893@ncsu.edu> <1991Mar30.225406.20493@dg-rtp.dg.com> <1991Apr3.142150.4445@athena.mit.edu> <9424@mentor.cc.purdue.edu> Reply-To: root@homer.ORG (Marc Brumlik) Organization: Tailored Software, Inc., Wheaton, IL Lines: 30 In article <9424@mentor.cc.purdue.edu> asg@sage.cc.purdue.edu (Bruce Varney) writes: ->But why are you all making this so hard????? ->Its easy. ->do this: ->---isempty--- ->#!/bin/sh ->dir=$1 ->num1=`ls -aF $dir | grep -v "/$" | wc -l` ->num2=`expr \`ls -lad $dir | cut -c12-13\` - 2 ` ->num=`expr $num1 + $num2` ->if [ $num = "0" ] ->then -> echo The directory is empty ->else -> echo The directory is not empty ->fi ->---isempty--- it can be even easier than this... how about: cd $1 files=`echo *` if [ "Z$files" = "Z" ] then echo "empty" else echo "not empty" fi -- ..{util20,obdient}!homer!marc Marc Brumlik, Tailored Software, Inc. Wheaton, IL Voice: 708 668 9947