Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: glob qualifier '-' doesn't work correctly on dangling symlinks



On 2020-04-12 18:34:48 +0100, Stephane Chazelas wrote:
> 2020-04-12 16:25:44 +0200, Vincent Lefevre:
> [...]
> > > 	  by the link, and not the link itself. If the
> > > 	                                        ^^^^^^
> > > 	  referenced file does not exist, the file information
> > > 	  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > > 	  and type shall be for the link itself.
> > > 	  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > 
> > At least, that's explicit, unambiguous documentation.
> [...]
> 
> Well, as seen in the varying interpretations made by the various
> implementations, it is not that clear. How do you determine
> whether a file exists or not? What does "exist" mean?

You necessarily know it, or that's an error case (permission denied
or whatever). The behavior may not be clear in case of error, but
one can expect at least a non-zero exit status:

  EXIT STATUS

    The following exit values shall be returned:

     0
        All path operands were traversed successfully.
    >0
        An error occurred.

As a comparison, for "test -e"

  https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

POSIX does not say "true if file exists" but conditions the result
to the pathname resolution, so that the result is false if any error
occurs, even if the file actually exists:

  -e  pathname
    True if pathname resolves to an existing directory entry.
    False if pathname cannot be resolved.

BTW, I don't know how zsh behaves on "[[ -e pathname ]]" in case of
error other than ENOENT in the pathname resolution, but this should
be documented (and ditto for the other conditional expressions).

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



Messages sorted by: Reverse Date, Date, Thread, Author