[Top][All Lists]

[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: Thu, 3 Oct 2013 17:04:17 -0700 (PDT)
User-agent: G2/1.0

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.


# cleanup
chmod -R 777 X
rm -rf X

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

if [ -e X/Y/file ]; then
echo X/Y/file exists

if [ -e X/Y/notafile ]; then
echo X/Y/notafile exists

find X

cat: X/Y/file: Permission denied
cat: X/Y/notafile: Permission denied
cat: X/f: Permission denied
X/f exists
find: `X/Y': Permission denied

reply via email to

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