tech-userlevel archive

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

"test -e" tests target of symlink


test(1) says:

     -e file       True if file exists (regardless of type).


$ ls -l /tmp/foo /tmp/bar
ls: /tmp/foo: No such file or directory
lrwx------  1 jschauma  wheel  8 May  4 11:35 /tmp/bar -> /tmp/foo

I would have expected "test -e /tmp/bar" to evaluate to true.  Instead,
it follows the symlink and evaluates to false:

$ test -e /tmp/bar
$ echo $?

IOW, it uses stat(2) instead of lstat(2):

        if (mode == FILSYM ? lstat(nm, &s) : stat(nm, &s))

(mode == FILSYM only if "-L" or "-h" was given)

Is this intentional, and if so, should this maybe be explicitly noted in
the manual page?


Attachment: pgpstrh4fktHM.pgp
Description: PGP signature

Home | Main Index | Thread Index | Old Index