Bash How to Wait Seconds

Bash How to Wait Seconds

How can we in the script wait for it until the system completes some tasks? The answer is to use sleep. This command suspends the script so that the script is low almost no system resources. Timing is sufficient.

Do you want to wait some seconds? In the next example, we will wait one second:

sleep 1

To turn off the script only for a split second? You can. This example shows the ingested sleep 100ms:

sleep 0.1

In this example, we will wait 20 minutes:

sleep 20m

In the next example, we will wait 8 hours:

sleep 8h

Do you want to wait several days? This is possible if you use a parameter d. However, consider using a cron scheduler. It is robust. Can you schedule to run it in your scripts at specified times and periodic runs?

In the last example, we will wait 7 days:

sleep 7d

Bash provides command wait to wait for the process/processes given as arguments:

wait $PID

PID is processing ID. ‘wait ${!}’ waits until the last background process is completed.

Leave a Comment