[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: best way to test for empty dir?
From: |
Sven Mascheck |
Subject: |
Re: best way to test for empty dir? |
Date: |
Fri, 11 Dec 2009 13:52:33 +0100 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
On Fri, Dec 11, 2009 at 12:31:49PM +0000, pk wrote:
> Marc Herbert wrote:
> > is_file3()
> > {
> > for f
> > do
> > [ -e "$f" -o -L "$f" ] && return
> > done
> > return 1
> > }
>
> You might also want to enable "dotglob" to catch hidden files...
empty=yes
for i in .?* *
do
test "$i" = '..' || test -e "$i" && empty=no && break
done
and with test -L added as needed.
Or (beacuse test -e is not strictly traditionally available)
and without special glob options:
empty=no
for i in .* * ; do
case "$i" in
.|..) : ;;
\*) for i in ? ; do
test "$i" = \? && empty=yes ; break
done ; break ;;
*) break ;;
esac
done
or just (if builtins-only is not strictly required)
test -z "`find . ! -name . -prune | sed q`"
comp.unix.shell might match well here and could be entertaining -
IMHO worth to migrate; objections?
- best way to test for empty dir?, Marc Herbert, 2009/12/10
- Re: best way to test for empty dir?, Greg Wooledge, 2009/12/10
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/10
- Re: best way to test for empty dir?, Chris F.A. Johnson, 2009/12/10
- Message not available
- Re: best way to test for empty dir?, pk, 2009/12/10
- Re: best way to test for empty dir?, pk, 2009/12/10
- Re: best way to test for empty dir?, Marc Herbert, 2009/12/11
- Message not available
- Re: best way to test for empty dir?, pk, 2009/12/11
- Re: best way to test for empty dir?,
Sven Mascheck <=
- Re: best way to test for empty dir?, Chris F.A. Johnson, 2009/12/11
- Re: best way to test for empty dir?, Sven Mascheck, 2009/12/11
- Re: best way to test for empty dir?, Marc Herbert, 2009/12/11
- Re: best way to test for empty dir?, Greg Wooledge, 2009/12/11
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/11
- Re: best way to test for empty dir?, Andreas Schwab, 2009/12/12
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/12
- Re: best way to test for empty dir?, Marc Herbert, 2009/12/14
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/14
- Re: best way to test for empty dir?, Andreas Schwab, 2009/12/15