In Bash, the
sleep command is used to introduce a delay or pause in the execution of a script or command. It allows you to specify a time interval in seconds, minutes, hours, or a combination thereof. The
sleep command is particularly useful when you need to introduce a delay between consecutive steps or add a time-based pause in your script.
The basic syntax of the
sleep command is as follows:
<duration> represents the time interval for which the script will pause. It can be specified in seconds (s), minutes (m), hours (h), or a combination thereof. For example:
echo "Hello" sleep 2s echo "World"
In this example, the script will print “Hello,” then pause for 2 seconds using
sleep 2s, and finally print “World” after the pause.
Here are a few more examples illustrating different ways to use the
# Pause for 5 seconds sleep 5 # Pause for 1 minute and 30 seconds sleep 1m30s # Pause for 3 hours and 15 minutes sleep 3h15m
sleep command allows you to control the timing and flow of your script by introducing delays at specific points. It is particularly useful when you want to create timed interactions, simulate processes, or control the rate of execution.