Semantics of test

Jaap Akkerhuis jaap at mcvax.UUCP
Fri Nov 8 10:46:52 AEST 1985


In all the unix systems I know about there was the program test, to be used
inside shell programs.

test -w foo will return the exit status 0 when foo is writable.

However, if foo is a directory, and although I have permission to write in
the directory, it will have the exit status 1.
Odd as it seems at first hand, it can be interpret as correct. Even if you
own the directory, you cannot copy an arbitrary file "on top of it". (Your
file system would be seriously be corrupted). Let us call this the purist
view.

Another interpretation is that if you can create a file in the directory, the
directory can be considered writable. Let us call this the sloppy view.

Shells with a build in "test" command, like the sysV and the ksh take the
sloppy view.

These different interpretations of test -w give a problem in porting shell
programs.

Question: What to do. Change "test", so it will be sloppy or should the shells
	with build in "test" be reformed to take the purist view.


	Jaap Akkerhuis (mcvax!jaap)

PS. Of course, if I have a shell file which would take care of the
    interpretation differences, I would use /bin/test in all cases. But since
    AT&T in their infinite wishdom removed /bin/test, this is going to be
    a pain:
	if test -f /bin/test
	then
		TEST=/bin/test	#purist test found
	else
		TEST=test	#sloppy test found
	fi

    The rest is left as an exercise to the reader.



More information about the Comp.unix.wizards mailing list