-e and permission denied
-e will return file not exists, even if it does, when permission denied error happen. I am wondering if this documented/correct behaviour or no. this behaviour seems poorly documented in manual http://www.gnu.org/software/bash/manual/bash.html but butter documented here http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
Bash 4.2 completion fails with failglob option enabled
Hello, everyone. bash 4.2 completion misfunctions with failglob option enabled. This problem doesn't occur in bash 3.2. Is failglob meant to be used in interactive shell? $ bash --version GNU bash, version 4.2.0(1)-release (i686-pc-linux-gnulibc1) $ # failglob is unset $ # completion fails $ shopt -u failglob $ touch asd123 $ echo asd??? asd123 ~ $ echo asdf??? asdf??? $ ls .bash .bash_history .bash_logout .bashrc.bashrc~ $ # failglob is set $ # completion fails $ shopt -s failglob $ echo asd??? asd123 $ echo asdf??? -bash: no match: asdf??? $ ls .babash: no match: words[0]=${!ref}${COMP_WORDS[i]} Thank you for considering my request.
Bash 4.2 completion fails with failglob option enabled
Hello, everyone. bash 4.2 completion misfunctions with failglob option enabled. This problem doesn't occur in bash 3.2. Is failglob meant to be used in interactive shell? $ bash --version GNU bash, version 4.2.0(1)-release (i686-pc-linux-gnulibc1) $ # failglob is unset $ # completion fails $ shopt -u failglob $ touch asd123 $ echo asd??? asd123 ~ $ echo asdf??? asdf??? $ ls .bash .bash_history .bash_logout .bashrc.bashrc~ $ # failglob is set $ # completion fails $ shopt -s failglob $ echo asd??? asd123 $ echo asdf??? -bash: no match: asdf??? $ ls .babash: no match: words[0]=${!ref}${COMP_WORDS[i]} Thank you for considering my request.
Re: -e and permission denied
On Thu, Oct 03, 2013 at 03:18:16AM -0700, vic...@vsespb.ru wrote: > -e will return file not exists, even if it does, when permission denied error > happen. I am wondering if this documented/correct behaviour or no. I assume you mean that bash will return 1 (failure) for [[ -e /path/to/file ]] when bash does not have search/execute privileges on all the directories in /path/to/. In which case, bash cannot stat() the file to see whether it exists. imadev:~$ mkdir -p /tmp/a/b/c imadev:~$ touch /tmp/a/b/c/file imadev:~$ [[ -e /tmp/a/b/c/file ]]; echo $? 0 imadev:~$ chmod 000 /tmp/a/b/c imadev:~$ [[ -e /tmp/a/b/c/file ]]; echo $? 1 How else would you expect bash to handle this?
Re: -e and permission denied
пятница, 4 октября 2013 г., 1:27:28 UTC+4 пользователь Greg Wooledge написал: > I assume you mean that bash will return 1 (failure) for [[ -e /path/to/file ]] yes > How else would you expect bash to handle this? Point was that it's probably poorly documented: "-e True if file exists." ( http://www.gnu.org/software/bash/manual/bash.html ). It's not immediately clear that false is returned if file exists but permission denied error happens.
Re: -e and permission denied
On 10/03/2013 03:36 PM, vic...@vsespb.ru wrote: > пятница, 4 октября 2013 г., 1:27:28 UTC+4 пользователь Greg Wooledge написал: >> I assume you mean that bash will return 1 (failure) for [[ -e /path/to/file >> ]] > > yes > >> How else would you expect bash to handle this? > > Point was that it's probably poorly documented: "-e True if file exists." ( > http://www.gnu.org/software/bash/manual/bash.html ). > > It's not immediately clear that false is returned if file exists but > permission denied error happens. For all intents and purposes, if you don't have permission to stat a file, then it may as well not exist. Treating permission denied as not existing is perfectly logical. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: -e and permission denied
пятница, 4 октября 2013 г., 2:11:51 UTC+4 пользователь Eric Blake написал: > For all intents and purposes What about the following intent: -if file exists, backup file -throw an error in case of permission problem (to avoid missing files in the backup destination) ?
Re: -e and permission denied
On 10/03/2013 04:19 PM, vic...@vsespb.ru wrote: > пятница, 4 октября 2013 г., 2:11:51 UTC+4 пользователь Eric Blake написал: >> For all intents and purposes > > What about the following intent: > -if file exists, backup file > -throw an error in case of permission problem (to avoid missing files in the > backup destination) > ? And how do you propose to back up a file that you do not have permission to access? For all intents and purposes, the file may as well not exist in the first place. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: -e and permission denied
On Friday, October 4, 2013 2:36:33 AM UTC+4, Eric Blake wrote: > On 10/03/2013 04:19 PM, vic...@vsespb.ru wrote: > > What about the following intent: > > > -if file exists, backup file > > > -throw an error in case of permission problem (to avoid missing files in > > the backup destination) > > > ? > And how do you propose to back up a file that you do not have permission > > to access? For all intents and purposes, the file may as well not exist > > in the first place. > I described use-case when user needs to *throw an error* when backup is impossible. That's important to know that backup failed in this use-case.
Re: -e and permission denied
On 10/03/2013 05:12 PM, vic...@vsespb.ru wrote: >> > I described use-case when user needs to *throw an error* when backup is > impossible. If test -e fails, backup is impossible. Throw an error in that case. > > That's important to know that backup failed in this use-case. I don't see the distinction. Either you have access to a file to attempt to back it up, or you don't. It doesn't matter why you don't. If you don't have access, then you cannot tell whether the file exists or not. So you might as well assume it does not exist, and write your script to error out if a user feeds you a name that you cannot access. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
Re: -e and permission denied
On Friday, October 4, 2013 3:24:35 AM UTC+4, Eric Blake wrote: > If you don't have access, then you cannot tell whether the file exists > or not. So you might as well assume it does not exist, and write your > script to error out if a user feeds you a name that you cannot access. if you have access: - if file exists - backup, if file does not exist - all ok. if you don't have access: - you are not sure if file exists or no, throw error just in case (to ask user to fix permission or file list) Command like "find" warns about permission denied errors, so, probably "find" programmers found a case when not exists vs unaccessible is matters. Also, sometimes -e reports that file exists even if it's unreadable (example below), so one might have expiration that his script properly cathes IO errors. == #!/bin/bash # cleanup chmod -R 777 X rm -rf X #/cleanup mkdir X mkdir X/Y touch X/Y/file touch X/f chmod 000 X/Y chmod 000 X/f cat X/Y/file || echo FAIL1 cat X/Y/notafile || echo FAIL2 cat X/f || echo FAIL3 if [ -e X/f ]; then echo X/f exists fi if [ -e X/Y/file ]; then echo X/Y/file exists fi if [ -e X/Y/notafile ]; then echo X/Y/notafile exists fi find X == == cat: X/Y/file: Permission denied FAIL1 cat: X/Y/notafile: Permission denied FAIL2 cat: X/f: Permission denied FAIL3 X/f exists X X/f X/Y find: `X/Y': Permission denied ==
Re: -e and permission denied
On Friday, October 4, 2013 4:04:17 AM UTC+4, vic...@vsespb.ru wrote: > one might have expiration * inspiration
Re: -e and permission denied
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