[Top][All Lists]

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

Re: SECONDS=0 does not reset SECONDS, or I'm missing something

From: Chet Ramey
Subject: Re: SECONDS=0 does not reset SECONDS, or I'm missing something
Date: Fri, 5 Jun 2020 11:51:00 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.8.0

On 6/4/20 6:01 PM, Andreas Kusalananda Kähäri wrote:

>> Yes, SECONDS is in seconds granularity, whether that is seconds since the
>> epoch or seconds since an assignment to it, as you quoted below. There's
>> no expectation of subsecond granularity -- it's just whatever the system
>> tells the shell the current number of seconds is.
>> The next version will use the number of seconds returned from gettimeofday,
>> but there's still nothing in there that attempts to round it up or down
>> depending on tv_usec.
> Oh, I'm not expecting subsecond granularity!  I'm expecting that
>       SECONDS=0; sleep 0.5; echo $SECONDS
> always outputs a zero, which it does not do now if the system's clock
> rolls over to a new full second during the 0.5 seconds of sleep.

I understand; that's why I said the shell uses whatever the system tells
it the number of seconds since the epoch is.

> It's just a bit odd to have the SECONDS parameter tick with the system
> time, which IMHO is not implied by the words "number of seconds since
> the assignment", that's all.

It looks like the problem is mismatched expectations. That's pretty common.

So we have several options: update the documentation to specify that the
system clock is used to determine the number of seconds; get a patch to
the devel branch to change the behavior; or use one of the other available

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU

reply via email to

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