[comp.unix.questions] BSD vs SysV -- [ -w <dir> ] different?

scs@itivax.iti.org (Steve Simmons) (12/12/89)

I've run into what appears to be an incompatibility between SysV and
BSD (and Ultrix), and wanted to get some feedback:

Given a directory foo, with permissions 777 and owned by root, running
as root the following bourne shell script gives different results:

#!/bin/sh
if [ -w foo ] ; then
	echo It is writable
else
	echo It is not writable
fi

On Ultrix 3.0 (DecStation 3100, largely BSD) and UNIX V.2 (UNIX-PC) the
result is 'It is writable'.  On BSD (VAX 785, unmodified /bin/sh) the result
is 'It is not writable'.  Is this correct?  And if so, why?
-- 
Steve Simmons	       scs@iti.org         Industrial Technology Institute
	'"You're not a big name on Usenet until someone puts
	  you in their .sig file."		-- Anonymous'

martin@mwtech.UUCP (Martin Weitzel) (12/14/89)

In article <4640@itivax.iti.org> scs@itivax.iti.org (Steve Simmons) writes:
>I've run into what appears to be an incompatibility between SysV and
>BSD (and Ultrix), and wanted to get some feedback:
>
>Given a directory foo, with permissions 777 and owned by root, running
>as root the following bourne shell script gives different results:
>
>#!/bin/sh
>if [ -w foo ] ; then
[rest deleted]

Obviously, there are too ways to define "writable":
1) Will I be able to open the file for writing?
2) Will I have the possibility to *change* the contents?

Because of the special nature of directories in UNIX, these two
questions must be answered differently (even to the Super-User):

1) You are *not* allowed to open a directory-file for writing, but
2) you *may* be able to change its contents with system services
   like "creat" (create new file) "link" and "unlink".

Now, SysV takes the one interpretation, BSD the other. As much as
I know, this problem occured allready in XENIX, when they shifted
from the external 'test'-command to the internal '[...]'-feature
of the shell (in System III). Some command scripts, that were
blindly converted (to achieve better performance) just went
the wrong way then.

IMHO, many many unix consultants (as me) would have no work, if
such inconsistencies were ommitted from the systems ... :-)
-- 
<<< MW -- email: see header -- voice: 49-(0)6151-6 56 83 >>>