test(1) and inconsistencies

Ed Gronke epg at cwi.nl
Tue Feb 9 02:17:35 AEST 1988


A query for people out there about test(1) and the interpretation
of a particular phrase on the manual page, specifically,

"-w file   true if the file exists and is writeable" (4.3 BSD)

"-w file   true if file exists and is writable" (Sun OS 3.2)

Now, these same options do two different things on Sun's running
Sun OS and on Vaxes (and CCI's) running 4.3 when applied to a writeable
directory (like /tmp)

Try the following -- (shell script)

if /bin/test -w /tmp
then 
echo write permission on /tmp
else
echo no write permission on /tmp
fi

On Sun's, this returns the message "write permission on /tmp" and on
4.3 it returns "no write permission on /tmp". 

Now, on 4.3, the reason it does it is because the test 
for "writeability" (sp?) is 
to attempt to open the file for writing (which of course fails for a
directory). I don't have the Sun source to check how they do it.

But, which is right (or write -:))? (I think Sun is right because of
the following question? )

And, if 4.3 is right,
how do you test for write permission on a directory in the shell?

-- Ed Gronke (epg at mcvax.cwi.nl) (Centrum voor Wiskunde en Informatica)



More information about the Comp.unix.wizards mailing list