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