I am writing a bash script which simply needs to sleep for less than a second. However 'sleep' only accepts seconds as input.
Is there any command to sleep less than 1000 ms?
sleep
from GNU Core Utilities does accept decimal numbers. From sleep(1):
Pause for NUMBER seconds. SUFFIX may be
s
for seconds (the default),m
for minutes,h
for hours ord
for days. NUMBER need not be an integer. Given two or more arguments, pause for the amount of time specified by the sum of their values.
I also tested BusyBox version of sleep
and confirmed that it also supports decimal numbers. This should clear any issues with even Alpine Linux.
The easiest workaround I could find is using bash's read builtin, which accepts milliseconds:
read -t 0.5
or with non bash scripts, for example fish:
bash -c 'read -t 0.5'