tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: test a -nt b if b doesn't exist



> Is there any consnsus among shell developers what the preferrd
> behaviour is?

I think it should match /bin/test, since making test a shell builtin is
supposed to be just an optimization.  (Incidentally, this means that,
from this point of view, as you described it, bash on NetBSD is buggy.)

Arranging that, when sh and test are not maintained together, is
admittedly...difficult.  In NetBSD's case, of course, this is less
difficult; perhaps an automated test to verify that /bin/test and the
shell builtin work the same way would be good?

As for which behaviour - whether shell builtin or /bin/test - is
better?  I'm not sure.

There are four existence cases: first file existing or not, cross
product with second file existing or not.  I agree that the case you
started off asking about is the only interesting one; if the first file
doesn't exist, I'd say the test is false regardless of whether the
second file exists, and if they both exist, it depends on the
timestamps.

Personally, I'd tend to treat a nonexistent second file as an
infinitely old second file: -nt is true and -ot is false.

Just to complicate things, you/we might arguably want A -nt B to be the
same as B -ot A, which disagrees with the above two paragraphs.

> At least, I think sh's behaviour should be documented (if only in the
> sense that it's undefined).

That, I totally agree with.

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse%rodents-montreal.org@localhost
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index