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: Fri, 11 Dec 2009 23:03:55 -0200

On Fri, 11 Dec 2009 16:16:13 +0000
Marc Herbert <address@hidden> wrote:

> Sven Mascheck a écrit :
> > Chris F.A. Johnson wrote:
> > 
> >> This has been discussed more than once in c.u.s; check the
> >> archives.
> > 
> > and that's why we better discuss it here now?
> 
> I think Chris' message was more like: "let's not discuss it at all and
> just read the archives"  :-]
> 
> 
> In case anyone is interested my winner (so far) is:
> 
> exists()
> {
>     [ -e "$1" -o -L "$1" ]
> }
> 

The -L is redundant.  Because, if the symlink is not broken, the regular file 
"exists" ( -e ).

A solution to check the broken symlink is:

[ -e "foo" -o -L "foo" -a ! -e "foo" ]

> if exists foo/*; then
>   for f in foo/*; do
>     ...
>   done
> fi
> 
> 
> 

-- 
Matias A. Fonzo <address@hidden>




reply via email to

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