sleep: Usage, Options & Common CI Errors
sleep pauses the script for the given amount of time, then continues.
sleep is the simplest way to wait - for a service to boot, between retries, for eventual consistency. In CI it is also a smell: a fixed sleep wastes minutes and is flaky; poll instead.
What it does
sleep suspends execution for a duration. GNU sleep accepts fractional seconds and unit suffixes; it is used for backoff between retries and for crude waits on services that are coming up.
Common usage
sleep 5 # 5 seconds
sleep 0.5 # half a second (GNU)
sleep 2m # 2 minutes (s/m/h/d, GNU)
# better than a blind sleep: poll until ready
until curl -fsS http://localhost:8080/health; do sleep 2; doneOptions
| Item | What it does |
|---|---|
| N | Seconds (integer) |
| N.M | Fractional seconds (GNU) |
| Ns / Nm / Nh / Nd | Seconds/minutes/hours/days (GNU suffixes) |
| sleep a b c | Sum of all durations (GNU) |
Common errors in CI
POSIX sleep takes only whole seconds - sleep 0.5 and suffixes like sleep 2m are GNU extensions and error on some BusyBox/BSD builds ("sleep: invalid number"). The bigger issue is design: a fixed sleep 30 either wastes runner minutes or is too short and flaky; replace it with a bounded poll (until ... do sleep 2; done with a timeout) so the job proceeds the instant the dependency is ready.