[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/
- Re: Potentially misleading documentation of SECONDS variable, (continued)
- Re: Potentially misleading documentation of SECONDS variable, alex xmb sw ratchev, 2024/08/06
- Re: Potentially misleading documentation of SECONDS variable, Koichi Murase, 2024/08/06
- Re: Potentially misleading documentation of SECONDS variable, alex xmb sw ratchev, 2024/08/06
- Re: Potentially misleading documentation of SECONDS variable, bash, 2024/08/06
- Re: Potentially misleading documentation of SECONDS variable, Chet Ramey, 2024/08/07
- Re: Potentially misleading documentation of SECONDS variable, G. Branden Robinson, 2024/08/07
- Re: Potentially misleading documentation of SECONDS variable, Chet Ramey, 2024/08/07
- Re: Potentially misleading documentation of SECONDS variable, felix, 2024/08/15
- Re: Potentially misleading documentation of SECONDS variable, Bash-help, 2024/08/15
- Re: Potentially misleading documentation of SECONDS variable, Martin D Kealey, 2024/08/18
Re: Potentially misleading documentation of SECONDS variable,
Chet Ramey <=
Re: Potentially misleading documentation of SECONDS variable, Ángel, 2024/08/06