help-bash
[Top][All Lists]
Advanced

[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: Thu, 4 Jun 2020 14:34:35 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.8.1

On 6/4/20 6:14 AM, Andreas Kusalananda Kähäri wrote:

>       #!/usr/local/bin/bash -x
> 
>       for name do
>               SECONDS=0
>               rm -r -f "$name"
>               [[ SECONDS -gt 0 ]] && sleep "$SECONDS"
>       done
> 
> What I noticed was that the script would go to sleep for a second
> every second, even if the deletion of directories was quick.  This
> indicates that SECONDS=0 didn't properly reset the SECONDS timer.  Or,
> it indicates that the timer is set by the system's clock (the current
> second according to the current time), and that it is not a real "timer"
> at all. 

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.

-- 
``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]