[Top][All Lists]

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

Re: bash "test" -nt and -ot operators mishandle nonpositive timestamps

From: Paul Eggert
Subject: Re: bash "test" -nt and -ot operators mishandle nonpositive timestamps
Date: Tue, 26 Feb 2002 21:01:15 -0800 (PST)

[I'm adding David Korn to the CC: list of this thread, since it seems
 we've now encountered one or two ksh93 bugs; please see the end of
 this message.  David, the original Bash bug report is:

           The "-ot" and "-nt" operators of the "test" command mishandle
           the case where one file has a nonpositive timestamp and the
           other file does not exist.  Files that do not exist should
           always be considered to be older than files that do exist.

> From: "Brian J. Fox" <address@hidden>
> Date: Tue, 26 Feb 2002 16:00:07 -0800
> Why should non-existant files be older than existing files?
> Why not the other way around?

Sorry, I don't know the underlying motivation, so I'll have to answer
"because ksh93 documents it to behave that way."  The ksh93 sh(1) man
page says:

  file1 -ot file2
    True, if file2 exists and file1 does not, or file1 is older than

The current Bash code attempts to implement this spec, but it
mishandles files with nonpositive time stamps since it incorrectly
assumes that a time stamp of 0 precedes the time stamp of any existing

ksh93 does not implement its own spec correctly either, but I think
Bash should implement the ksh93 spec, not the ksh93 behavior, which is
clearly inconsistent.

For example, here's what /bin/ksh does on my Solaris 8 host (running
in 32-bit mode):

   $ mkdir d
   $ cd d
   $ export TZ=UTC0
   $ touch -m -t 190112132045.52 oldest
   $ touch -m -t 190112132045.53 old
   $ touch -m -t 197001010000.00 epoch
   $ touch -m -t 203801180314.07 newest
   $ ls -ltr *
   -rw-rw-r--   1 eggert   eggert         0 Dec 13  1901 oldest
   -rw-rw-r--   1 eggert   eggert         0 Dec 13  1901 old
   -rw-rw-r--   1 eggert   eggert         0 Jan  1  1970 epoch
   -rw-rw-r--   1 eggert   eggert         0 Jan 18  2038 newest
   $ test oldest -ot newest || echo bug
   $ test nonexistent -ot old || echo bug
   $ test oldest -ot nonexistent && echo bug
   $ test nonexistent -ot epoch || echo bug

Solaris 8 ksh fails all four tests.  Without my patches, Bash passes
two of the four tests, and fails the other two.  But if you apply my
proposed patch to Bash, it passes all four tests.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]