[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: best way to test for empty dir?
From: |
Marc Herbert |
Subject: |
Re: best way to test for empty dir? |
Date: |
Mon, 14 Dec 2009 12:21:12 +0000 |
User-agent: |
Thunderbird 2.0.0.21 (X11/20090320) |
Matias A. Fonzo a écrit :
> On Fri, 11 Dec 2009 16:16:13 +0000
> Marc Herbert <Marc.Herbert@gmail.com> wrote:
>> In case anyone is interested my winner (so far) is:
>>
>> exists()
>> {
>> [ -e "$1" -o -L "$1" ]
>> }
>>
>
> The -L is redundant.
Not for me. I need -L because I want to consider broken symlinks just
like anything else. A broken symlink would be a bug in my code and I want to
detect it ASAP.
> Because, if the symlink is not broken, the regular file "exists" ( -e ).
Please forget about correct symlinks. The -L is here for *broken*
symlinks.
> A solution to check the broken symlink is:
>
> [ -e "foo" -o -L "foo" -a ! -e "foo" ]
For which type of "foo" object does this return a different value than
the above? None.
If common sense is not enough, here is a formal proof that your third
and last test is redundant:
-e or (-L and ! -e) == (-e or -L) and (-e or ! -e) distributivity
(-e or -L) and 1 complements
-e or -L boundedness
<http://en.wikipedia.org/wiki/Boolean_logic#Properties>
- Re: best way to test for empty dir?, (continued)
- 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
- 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 <=
- 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
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/15
- Re: best way to test for empty dir?, Andreas Schwab, 2009/12/15
- Re: best way to test for empty dir?, Matias A. Fonzo, 2009/12/15
- Message not available
- Re: best way to test for empty dir?, Antonio Macchi, 2009/12/15
- Message not available
- Re: best way to test for empty dir?, Stephane CHAZELAS, 2009/12/12
- Re: best way to test for empty dir?, Stephane CHAZELAS, 2009/12/12
Message not available