bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -e test for file exists problem with dangling symlinks


From: Paul Eggert
Subject: Re: -e test for file exists problem with dangling symlinks
Date: Tue, 22 Feb 2005 15:45:18 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

"John R. Vanderpool" <address@hidden> writes:

> this will probably be considered a non-bug (because the same behavior
> exists in bash, ksh, pdksh, irix, and gnu coreutils!) but i'ld at least
> like to hear an explanation if possible.

It's longstanding tradition that "test -e foo" should fail on a
dangling symlink.  It's also a requirement of POSIX; see
<http://www.opengroup.org/onlinepubs/009695399/utilities/test.html>.

You can use "test -e FOO || test -h FOO" if you want to test for
either a file or a dangling symlink.  Admittedly this is less
efficient than you might like, if for some reason (e.g., a network
file system, or a slow device) stat calls are very expensive.  If you
want a nonstandard extension that just issues an lstat system call and
nothing else, you can use "stat -c '' FOO 2>/dev/null" (recent
coreutils versions only) to test whether FOO exists either as a file
or a dangling symlink, without following any symlinks.




reply via email to

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