To sleep or delay a specified amount of time in a Bash shell script, you can use the sleep
command followed by the number of seconds you want to sleep.
For example, to sleep for 5 seconds, you can use the following command:
sleep 5Soruce:www.lautturi.com
This will pause the script for 5 seconds before continuing.
You can also use the sleep
command to sleep for a fractional number of seconds. For example, to sleep for half a second, you can use the following command:
sleep 0.5
Keep in mind that the sleep
command only works with integer or fractional seconds. If you want to sleep for a longer period of time, you will need to use a loop to sleep for smaller increments of time.
For example, to sleep for 1 minute, you can use the following loop:
for i in {1..60}; do sleep 1 done
This will sleep for 1 second 60 times, which is equivalent to sleeping for 1 minute.
You can also use the sleep
command to sleep for a specified number of minutes or hours. For example, to sleep for 30 minutes, you can use the following command:
sleep 30m
To sleep for 1 hour, you can use the following command:
sleep 1h
Keep in mind that the sleep
command may not be precise, as it relies on the operating system's sleep function, which may not be accurate to the exact number of seconds or minutes specified.