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
Date: Fri, 27 Aug 2021 09:32:29 -0400 (EDT)
From: Mouse <mouse%Rodents-Montreal.ORG@localhost>
Message-ID: <202108271332.JAA25363%Stone.Rodents-Montreal.ORG@localhost>
| 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?
/bin/test and the test builtin to /bin/sh are the same source code,
so if they give different results, something very odd would be happening.
Edgar's question was more on what the definition of -nt should be, when
the 2nd arg file does not exist.
Our test defines -nt and -ot as being true only if the first arg file
exists, so if we want [ X -nt Y ] to give the same result as [ Y -ot X ]
in the case that one of the files does not exist, which is (aside from
the case that both files have the same mod time, a desirable property)
then the [ X -nt Y ] case when X exists and Y does not must be false
(because [ Y -ot X ] would be false under those conditions.
It is also not unreasonable to believe that a file cannot be newer than
something that doesn't exist, so returning false for [ X -nt Y ] when Y
does not exist is reasonable that way as well.
bash uses a different definition for -ot, where it is the 2nd arg
that needs to exist, instead of the first. Hence its results are
different.
But since no portable script can really use -nt (as it isn't standardised)
I'm not sure that this is all that important.
kre
Home |
Main Index |
Thread Index |
Old Index