[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
test -nt and -ot operators
Our man page for test says ...
file1 -nt file2
True if file1 exists and is newer than file2.
file1 -ot file2
True if file1 exists and is older than file2.
The code actually implements
True if file1 and file2 both exist, and file1 is ...
In ksh (all versions I think, including our /bin/ksh) which is (the original
ksh I mean, not our version) where (I think) the -nt/-ot operators originated
(where they were first invented) the test is
true if file1 exists and either file2 does not exist
or file1 is newer than file2
true if file2 exists and either file1 does not exist
or file1 is older than file2
(newer/older in all cases refer to the mtime field, and "exists" means,
in all cases, "stat(2) succeeds" which doesn't necessarily have anything
much to do with whether the files exist or not...)
For ref, FreeBSD is identical to NetBSD (code & doc). zsh seems to be the same
(both implmentation and doc, though I am guessing impl from behaviour.)
dash implements the same thing NetBSD & FreeBSD do, but documents it properly.
bash implements the ksh -nt/-ot (and documents that, as does ksh of course)
Any opinions on what we should do here (where "nothing" is an entirely
valid option)? Apart from nothing, any change is likely to include
"correctly document what is implemented" and then the question is just
what is best to actually implement?
In case it is not obvious (I hope it is) either version can be implemented
out of the other by adding extra tests, and it is possible to write a
sequence of tests which do whatever you want, which will work whichever
way the test -nt/-ot operators are implemented.
So a supplementary question is: Should we add something to the doc to
point out the difference in semantics, so people are aware of it (whichever
way we end up implementing) ?
ps: all of this is a POSIX extension, so POSIX is no help at all.
pps: on the off chance that anyone is wondering, some (most) of these recent
questions have arisen because i have been running tests developed for
other people's shells against our /bin/sh and investigating where we do
not do what they expect to happen.
Main Index |
Thread Index |