Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!cornell!uw-beaver!milton!ogicse!intelhf!ichips!iwarp.intel.com!gargoyle!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.unix.questions Subject: Re: How do I tell when a directory is empty in a script? Message-ID: <1991Apr01.160138.16162@chinet.chi.il.us> Date: 1 Apr 91 16:01:38 GMT Article-I.D.: chinet.1991Apr01.160138.16162 References: <1991Mar30.040400.13893@ncsu.edu> Organization: Chinet - Chicago Public Access UNIX Lines: 22 In article <1991Mar30.040400.13893@ncsu.edu> harris@catt.ncsu.edu (Michael Harris) writes: >When I am running a shell script, how can I tell when a directory is empty? >I tried looking at the output of ls -a but it includes . and .. Usually the reason I want to know this is that I plan to do something to all the visible files if there are any, so something like this will work using the builtin "echo" command and only require the directory to be read once. LIST=`echo *` if [ "*" = "$LIST" ] then : # no files - do nothing else for i in $LIST do .... # commands to process files done fi Les Mikesell les@chinet.chi.il.us