[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: best way to test for empty dir?
From: |
Matias A. Fonzo |
Subject: |
Re: best way to test for empty dir? |
Date: |
Thu, 10 Dec 2009 17:37:04 -0200 |
On Thu, 10 Dec 2009 17:31:20 +0000
Marc Herbert <Marc.Herbert@gmail.com> wrote:
> Hi,
>
Hello
> Does anyone know a more elegant way to check for file existence?
> Something that does not fork a subshell. And is also more readable
> maybe. And is obviously not much longer.
>
> empty_dir()
> {
> test "x$(echo $1/*$2)" = "x$1"'/*'"$2"
> }
>
>
> Warning: I find neither "noglob" nor "ls" elegant, sorry!
>
Maybe you want the Chris F.A Johnson's implementation [1]:
set -- "/tmp/emptydir"/*
[[ -f $1 ]] && echo non-empty || echo empty;
References:
[1]
http://www.issociate.de/board/goto/866027/checking_if_a_directory_is_empty.html
--
Matias A. Fonzo <selk@dragora.org>
- 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 <=
- 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, 2009/12/11
- 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