[Top][All Lists]

[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 (X11/20090320)

Matias A. Fonzo a écrit :
> On Fri, 11 Dec 2009 16:16:13 +0000
> Marc Herbert <address@hidden> 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*

> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]