bug-bash
[Top][All Lists]
Advanced

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

Re: Potentially misleading documentation of SECONDS variable


From: Chet Ramey
Subject: Re: Potentially misleading documentation of SECONDS variable
Date: Tue, 6 Aug 2024 15:58:35 -0400
User-agent: Mozilla Thunderbird

On 8/6/24 11:17 AM, Bash-help via Bug reports for the GNU Bourne Again SHell wrote:
Reading the manual at
<https://www.gnu.org/software/bash/manual/bash.html#Bash-Variables>
regarding the SECONDS variable, it states that
" [..] Assignment to this variable resets the count to the value assigned,
and the expanded value becomes the value assigned plus the number
of seconds since the assignment. [..]"

This implies that assigning the variable at time X with value Y would
reset SECONDS to Y. When expanding the variable at time X+Z the
value should be Y+Z. The text also implies whole seconds, i.e. not
milliseconds or other fractions of seconds, are considered. However, it would 
seem as if the
underlying mechanism to update SECONDS (the system clock)
are actually considering fractions of seconds and not whole seconds.

The system clock (at least on all of the systems worth considering at this
point) has always kept fractions of a second. Bash has never looked at
anything but whole seconds. From when I first added SECONDS in 1989 through
bash-5.1, it used time(3). In bash-5.1, I changed it to use the tv_sec member of the struct from gettimeofday (which is essentially what modern
versions of time(3) do), but it's never rounded up or attempted to perform
tv_usec or tv_nsec arithmetic.

If you're interested in that kind of sub-second precision, use
EPOCHREALTIME. If you want something that's not affected by assignment,
use EPOCHSECONDS.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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