I expect it's old, old news to those with more shell scripting scars: but
the results of the [ -e ] test are at variance with my allegedly reasonable
reading of the documentation.

For all three of sh, ksh, and the /bin/test manpages, the description of the
-e test reads "file exists", unlike the other file-related tests which read
"file exists and <further condition>", with <further condition> being
is-writable, is-exucatable, is-readable, and the like. The manpage for
/bin/test is even more emphatic in suggesting it's going to be true for a
strict superset of the files for which the other tests return true - "True
if file exsits (regardless of type)".

However, there are arguments for which -e returns false, but a different
file-related test returns true. These arguments are symlinks which don't
resolve to an existing file - both symlinks that point 'nowhere', i.e. to
non-existent targets (directly or indirectly), and symlinks which will error
with ELOOP if stat()ed.

Changing the behaviour of -e for non-resolving symlinks is almost certainly
a Really Bad Idea: the existing behaviour of -e is doubtless relied on by a
few million shellscripts, all more or less strongly bound to the idea that
if -e returns true, there's Something There, and a strong expectation that
the Something is stat()able rather than merely lstat()able. But perhaps a
small change to the venerable text of the sh, ksh, and /bin/test manpages
might be in order? Some form of words like "exists (target exists if a
symbolic link)" might capture the actual behaviour more accurately.

Yes, it's a picky point - and one I wouldn't bother raising in the Linux
world, where manpages are at best impressionistic; but the pithy clarity of
OpenBSD manpages is a pearl beyond price, and thus worth cleaning of even
small specks.

As far as testing in shell scripts whether 'things' are present - using
[ -e $file -o -h $file ] catches the 'exists, maybe as a symlink which
doesn't resolve' case; as could the use of stat(1) with suitable
format-strings, -q, -L, and related incantatia...

Cheers, Stefek

Reply via email to