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

Re: second-one-billion-bug ?



Jonathan Schmitt <jonathan.schmitt@detla.de> writes:

> In the first version of this script, the test was:
> 	if [[ `date -s $newest +%s` < `date -s $aux` +%s ]]
> and this one worked for one file, where all versions available were not older 
> than two weeks.

As James correctly surmised, the problem was that you were comparing
timestamps as strings rather than as numbers.

BAD:
        [[ `date -s $newest +%s` < `date -s $aux +%s` ]]
(compares timestamps as strings, leading to potential mis-sorting)

OK:
        [ `date -s $newest +%s` -lt `date -s $aux +%s` ]
(compares timestamps as numbers, leading to correct sorting)

BEST:
        [ $newest -of $aux ]
(simple and direct)

-- 
Aaron M. Ucko, KB1CJC (amu at alum.mit.edu, ucko at debian.org)
Finger amu@monk.mit.edu for more info.



Reply to: