Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!bierstadt.scd.ucar.edu!sog From: sog@bierstadt.scd.ucar.edu (Steve Gombosi) Newsgroups: comp.unix.questions Subject: Re: How do I tell when a directory is empty in a script? Message-ID: <11058@ncar.ucar.edu> Date: 16 Apr 91 00:04:10 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> <900@homer.UUCP> <1991Apr15.180550.14750@beaver.cs.washington.edu> Sender: news@ncar.ucar.edu Organization: Scientific Computing Division/NCAR, Boulder, CO Lines: 44 In article <1991Apr15.180550.14750@beaver.cs.washington.edu> pauld@cs.washington.edu (Paul Barton-Davis) writes: >In article <900@homer.UUCP> root@homer.ORG (Marc Brumlik) writes: > >>it can be even easier than this... how about: > [ deleted ] > >why not just: > > if [ "`cd $1 ; echo *`" ] ; then > echo "not empty" > else > echo "empty" > fi For an example of why this doesn't work, may I submit the following "script" output: Script started on Mon Apr 15 17:56:31 1991 bierstadt% mkdir dummy bierstadt% cd dummy bierstadt% cat>.xx1 ^D bierstadt% cat>.xx2 ^D bierstadt% ls bierstadt% ls -a . .. .xx1 .xx2 bierstadt% echo * echo: No match. bierstadt% exit bierstadt% script done on Mon Apr 15 17:57:24 1991 As you can see, directory "dummy" is NOT empty, but both a regular "ls" and "echo *" show it to be "empty". -- -- Steve Gombosi sog@bierstadt.ucar.edu | "The relationship between employer and employee, sgombosi@isis.cs.du.edu | like that between master and slave, is demeaning | to both" -- Edward Abbey