How do I tell when a directory is empty in a script?
Steve Gombosi
sog at bierstadt.scd.ucar.edu
Tue Apr 16 10:04:10 AEST 1991
In article <1991Apr15.180550.14750 at beaver.cs.washington.edu> pauld at cs.washington.edu (Paul Barton-Davis) writes:
>In article <900 at homer.UUCP> root at 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 at bierstadt.ucar.edu | "The relationship between employer and employee,
sgombosi at isis.cs.du.edu | like that between master and slave, is demeaning
| to both" -- Edward Abbey
More information about the Comp.unix.questions
mailing list