TrumanWong

sleep

Delay the current action for a period of time

Supplementary instructions

sleep command pauses for the specified time.

grammar

sleep(parameter)

Parameters

Time: Specify the length of time to pause, including the following:

  • 2s: 2 seconds
  • 2m: 2 minutes
  • 2h: 2 hours
  • 2d: 2 days
  • infinity: permanent

Example

Sometimes when writing some monitoring scripts that run in a loop, it is essential to set the time interval. The following is a script showing a Shell progress bar to generate a delay in the script.

#!/bin/bash

b=''
for ((i=0;$i<=100;i++))
  do
  printf "Progress:[%-100s]%d%%\r" $b $i
  sleep 0.1
  b=#$b
  done
echo