in reply to What conditions cause the -e file test to return false

One I thought would trip it up is doing a chmod 000 on a file owned by root and testing it existed using a non-root user. Nope, you still get the -e returning true. (Which does seem to be the desired semantics, since the file does exist.

Update: Ahh, here's a case. If the user running the script cannot cd into the directory containing the file, then -e fails.

  • Comment on Re: What conditions cause the -e file test to return false

Replies are listed 'Best First'.
Re^2: What conditions cause the -e file test to return false
by ikegami (Patriarch) on Feb 27, 2009 at 16:23 UTC
    Do chmod 000 on the directory containing the file and it won't be found for non-root users.
    $ perl -MErrno=ENOENT -le' $found = -e shift; die("stat: $!\n") if !defined($found) && $! != ENOENT; print($found ? "found" : "not found"); ' foo/bar not found $ touch foo/bar $ perl -MErrno=ENOENT -le' $found = -e shift; die("stat: $!\n") if !defined($found) && $! != ENOENT; print($found ? "found" : "not found"); ' foo/bar found $ chmod a-x foo $ perl -MErrno=ENOENT -le' $found = -e shift; die("stat: $!\n") if !defined($found) && $! != ENOENT; print($found ? "found" : "not found"); ' foo/bar stat: Permission denied