If you are using -e to test if a file is readable, then you're asking
the wrong question. If you want to know if a file is readable, use
the -r test.

if [ -r some/file ]; then
  ... do something with file that involves reading it ..
fi

Regarding the 'permission denied' errors, that's an *operating
system* issue. The operating system is (on purpose) not letting you
know if that file exists or not, because, if you don't have the
permission to check it, then you shouldn't get that information!
That's the whole point of having permissions on directories, to avoid
handling the list of files to users that don't have the permissions.

So, at the end, if the file exists or not, you as a user cannot know,
because it might, but you don't have permission to see it. So, don't
expect bash to circumvent O/S security mechanisms.

Better yet, most sane commands return a proper exit code when there
was an error. So, if you try to read the file, but the command
couldn't read it, then the command should return an error exit code,
and you can test things like this:

if program some/file; then
  everything went fine
else
  something went wrong...
fi

-- 
Eduardo A. Bustamante López

Reply via email to