[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: -e and permission denied
From: |
victor |
Subject: |
Re: -e and permission denied |
Date: |
Fri, 4 Oct 2013 02:18:05 -0700 (PDT) |
User-agent: |
G2/1.0 |
On Friday, October 4, 2013 5:10:43 AM UTC+4, Eduardo A. Bustamante López wrote:
> 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
> If you are using -e to test if a file is readable
no, I am not
> The operating system is (on purpose) not letting you know if that file exists
> or not
OS is not lying about file existence. It returns "permission denied" error,
which means file may or may not exist.
> Better yet, most sane commands return a proper exit code when there was an
> error
Whole issues was that -e behaviour is not properly documented ("-e True if
file exists." is simply not true),
so user won't know that he/she needs to use right command and right logic.
example of better documentation:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
"True if pathname resolves to an existing directory entry. False if pathname
cannot be resolved."
- Re: -e and permission denied, (continued)
- Re: -e and permission denied, Greg Wooledge, 2013/10/03
- Message not available
- Re: -e and permission denied, victor, 2013/10/03
- Re: -e and permission denied, Eric Blake, 2013/10/03
- Message not available
- Re: -e and permission denied, victor, 2013/10/03
- Re: -e and permission denied, Eric Blake, 2013/10/03
- Message not available
- Re: -e and permission denied, victor, 2013/10/03
- Re: -e and permission denied, Eric Blake, 2013/10/03
- Message not available
- Re: -e and permission denied, victor, 2013/10/03
- Re: -e and permission denied, victor, 2013/10/03
- Re: -e and permission denied, Eduardo A . Bustamante López, 2013/10/03
- Message not available
- Re: -e and permission denied,
victor <=
- Re: -e and permission denied, Chris Down, 2013/10/04
- Re: -e and permission denied, Eric Blake, 2013/10/04
- Message not available
- Re: -e and permission denied, victor, 2013/10/04