How do I pause my shell script for a second before continuing?

user3268208 picture user3268208 · Feb 7, 2014 · Viewed 943.3k times · Source

I have only found how to wait for user input. However, I only want to pause so that my while true doesn't crash my computer.

I tried pause(1), but it says -bash: syntax error near unexpected token '1'. How can it be done?

Answer

RydallCooper picture RydallCooper · Feb 7, 2014

Use the sleep command.

Example:

sleep .5 # Waits 0.5 second.
sleep 5  # Waits 5 seconds.
sleep 5s # Waits 5 seconds.
sleep 5m # Waits 5 minutes.
sleep 5h # Waits 5 hours.
sleep 5d # Waits 5 days.

One can also employ decimals when specifying a time unit; e.g. sleep 1.5s