[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: |
Tue, 15 Dec 2009 11:26:16 -0200 |
On Tue, 15 Dec 2009 15:23:33 +0100
Andreas Schwab <schwab@linux-m68k.org> wrote:
> "Matias A. Fonzo" <selk@dragora.org> writes:
>
> > On Tue, 15 Dec 2009 10:37:36 +0100
> > Andreas Schwab <schwab@linux-m68k.org> wrote:
> >
> >> "Matias A. Fonzo" <selk@dragora.org> writes:
> >>
> >> > On Mon, 14 Dec 2009 12:21:12 +0000
> >> > Marc Herbert <Marc.Herbert@gmail.com> wrote:
> >> >
> >> >> 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.
> >> >>
> >> >
> >> > The [ -L "foo" -a ! -e "foo" ] is a specific case to check dangling
> >> > symlinks.
> >>
> >> Combine that with the existence check and you have exactly the
> >> expression above.
> >>
> >
> > Not quite.
> >
> > Here an interesting quote from the Greg's FAQ:
> >
> > "The -e test (like all other tests besides -L or -h) follows the symbolic
> > link, and therefore it checks on the thing pointed to, not on the link
> > itself. The -L test does not follow the symlink, so it's checking on the
> > link itself. Together, they can indicate the presence of a dangling
> > symlink."
> >
> > You can see, creating a dangling symlink:
> >
> > $ ln -sf x y
> > $ sh -c '[ -e "y" ] && echo true || echo false'
> > false
> > $ sh -c '[ -L "a" ] && echo true || echo false'
> > true
>
Sorry, change the last "a" to "y". :-)
- Re: best way to test for empty dir?, (continued)
- 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, 2009/12/14
- 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 <=
- 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
Message not available