Advertisement
Advertisement


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


Question

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?

2017/10/20
1
730
10/20/2017 5:28:32 PM


And what about:

read -p "Press enter to continue"
2017/01/06

In Python (question was originally tagged Python) you need to import the time module

import time
time.sleep(1)

or

from time import sleep
sleep(1)

For shell script is is just

sleep 1

Which executes the sleep command. eg. /bin/sleep

2014/02/07

I realize that I'm a bit late with this, but you can also call sleep and pass the disired time in. For example, If I wanted to wait for 3 seconds I can do:

/bin/sleep 3

4 seconds would look like this:

/bin/sleep 4
2015/07/30

On Mac OSX, sleep does not take minutes/etc, only seconds. So for two minutes,

sleep 120
2017/08/23

Run multiple sleeps and commands

sleep 5 && cd /var/www/html && git pull && sleep 3 && cd ..

This will wait for 5 seconds before executing the first script, then will sleep again for 3 seconds before it changes directory again.

2018/09/19