On Mon, 14 Dec 2009 12:21:12 +0000 Marc Herbert <marc.herb...@gmail.com> wrote:
> Matias A. Fonzo a écrit : > > On Fri, 11 Dec 2009 16:16:13 +0000 > > Marc Herbert <marc.herb...@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. > > > 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