bug-bash
[Top][All Lists]
Advanced

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

Re: -e and permission denied


From: Eduardo A . Bustamante López
Subject: Re: -e and permission denied
Date: Thu, 3 Oct 2013 18:10:43 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

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

[Prev in Thread] Current Thread [Next in Thread]