SysN test != V7 test

Henry Spencer henry at utzoo.UUCP
Sat Mar 31 08:13:51 AEST 1984


One of the more interesting things done in System N (N = III or V just
now) was that "test" is built into the shell.  Although we don't run
System V, we do run a slightly-modified System V shell on our V7.  We
have just discovered a very interesting thing:  the test(1) command
that is built into the shell is not quite the same as the old separate
program.

The difference is that the old test(1) tested for accessability by
trying to open the file.  The in-shell one just uses access(2) to look
at the permission bits.  What difference is there, you ask?  Well...
There's a minor difference in the case of "test -w directory".  This
isn't too important, and the new behavior (actually look at the bits
rather than just bouncing it regardless) is arguably better.  The *real*
fun is when you are doing a test(1) on a device.

We discovered this because we had a few things that used to do, for
example, "test -r /dev/rmt0" to make the magtape rewind.  Don't work
no more.  This breaks things.  Not very many things, mind you, and we
don't see this as too serious issue.  However, consider the following.
Shell file, written on System V, does "test -w /dev/rmt0" to see if
it's running on a system with a magtape at a suitable name.  On a system
with the old-style test(1) command, this will write a tape mark at the
beginning of the tape, effectively obliterating any data on the tape!

Another fun property of using access(2) for test(1) is that access(2)
uses the real, not effective, userid.  This could make setuid shell
files (if you have them -- we don't) *very* interesting.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Net.bugs mailing list