bug-bash
[Top][All Lists]
Advanced

[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: Mon, 14 Dec 2009 15:30:51 -0200

On Mon, 14 Dec 2009 12:21:12 +0000
Marc Herbert <address@hidden> wrote:

> 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*
> symlinks.
> 

The [ -L "foo" -a ! -e "foo" ] is a specific case to check dangling 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.
> 

Is just an example.

> 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>
> 

Yeah logic.. I have intuition.

Regards,
Matías




reply via email to

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