coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] sleep: allow ms suffix for milliseconds


From: Bernhard Voelker
Subject: Re: [PATCH] sleep: allow ms suffix for milliseconds
Date: Sat, 30 Nov 2019 00:46:35 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2

On 2019-11-29 23:02, Bernhard Voelker wrote:
> On 2019-11-29 21:58, Kaz Kylheku (Coreutils) wrote:
>> Sleeping for 15500 milliseconds is valid.
>>
>> But in any case, we can already do that with "sleep 15.500".
>>
>> The issue is that it's cumbersome to convert from 15500 to 15.500
>> in a shell script.
> 
> This can easily be done ... with the shell's integer arithmetic
> and due to the fact the GNU sleep adds all arguments to the final
> nanosleep(2) time:
> 
>   $ x=15500
>   $ sleep  $((x/1000))  0.$((x%1000))

yet another variant:

  $ sleep $( echo $x | numfmt  --format='%.3f' --to-unit=1000)

so a shell function could look like:

  millisleep() { sleep $(echo "$@" | numfmt  --format='%.3f' --to-unit=1000); }

Have a nice day,
Berny



reply via email to

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