Re: best way to test for empty dir?

2009-12-14 Thread Matias A. Fonzo
On Mon, 14 Dec 2009 12:21:12 +
Marc Herbert  wrote:

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

Yeah logic.. I have intuition.

Regards,
Matías




Re: add a way to declare global variables

2009-12-14 Thread Bernd Eggink

Am 12/14/09 13:37, schrieb Marc Herbert:

Bernd Eggink a écrit :

To avoid misunderstandings, let me add that you are right (only) with
respect to variables being used _without_ declaration.


OK, but not having to explicitly "declare" variables is a feature that
most people expect from dynamic languages, so you can hardly blame them
for doing this all the time in shell.


I don't blame anybody. I'm talking about the fact that associative 
arrays are an exception from "what most people expect from dynamic 
languages", as they _have_ to be explicitly declared. This doesn't 
bother me, but I would prefer to have a choice between local and global 
declaration anyway.


--
Bernd Eggink
http://sudrala.de




Re: add a way to declare global variables

2009-12-14 Thread Marc Herbert
Bernd Eggink a écrit :
> To avoid misunderstandings, let me add that you are right (only) with 
> respect to variables being used _without_ declaration.

OK, but not having to explicitly "declare" variables is a feature that
most people expect from dynamic languages, so you can hardly blame them
for doing this all the time in shell.

IMHO Python gets this global/local (implicit) declaration story
right. Of course it is easier when you do not have 30 years of POSIX
legacy to support (but just the experience).







Re: best way to test for empty dir?

2009-12-14 Thread Marc Herbert
Matias A. Fonzo a écrit :
> On Fri, 11 Dec 2009 16:16:13 +
> Marc Herbert  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 -Lboundedness