testing if a directory is empty (OOOPS!)
Paul Barton-Davis
pauld at stowe.cs.washington.edu
Wed Apr 17 03:33:14 AEST 1991
In article <MEISSNER.91Apr15221545 at curley.osf.org> meissner at osf.org (Michael Meissner) writes:
>In article <1991Apr15.195513.17840 at beaver.cs.washington.edu>
>pauld at cs.washington.edu (Paul Barton-Davis) writes:
>
[ my stupid idea deleted ]
>
>It still isn't any reason to fail. Off of the top of my head, the
>following should work:
>
> [ "`cd $1; echo .[^.] .??* *`" = ".[^.] .??* *" ]
>--
>Michael Meissner email: meissner at osf.org phone: 617-621-8861
>Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142
>
>Considering the flames and intolerance, shouldn't USENET be spelled ABUSENET?
I may be wrong, but it seems regrettably not. From the man page for csh(1):
The sequence `[...]' matches any one of the characters enclosed.
Within `[...]', a pair of characters separated by `-' matches any
character lexi- cally between the two.
and from sh(1):
[ ... ]
Matches any one of the characters enclosed. A pair of char-
acters separated by - matches any character lexically
between the pair.
These shell's don't know about the "[^" convention, and indeed:
# echo .[^.]
.. <can someone explain this>
# echo .[^f]
echo: No Match
Your guess is as good as mine. What will work, for 7-bit systems
anyway, is:
echo .[^@--/-~]* *
This matches ALL dots files except . and ... Unfortunately, my csh
(Ultrix 4.1) doesn't handle the inclusion of ascii 127 (DELETE) in
this list very graciously, and if you have non-ASCII (> code 127)
chars in any dot file file name, this will also break. I increasingly
feel that the "rmdir; if [ $? ..." approach is the best way to
crack this.
--
Paul Barton-Davis <pauld at cs.washington.edu>
UW Computer Science Lab ``to shatter tradition makes us feel free''
More information about the Comp.unix.questions
mailing list