Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

shell

unix

People also ask

How do I pause a shell script?

There is no pause command under Linux/UNIX bash shell. You can easily use the read command with the -p option to display pause along with a message.

How do you pause a Bash script while running?

Use the -t command and the number of seconds to pause the script. We are also including the -p option and some informative text in this example, but it is not strictly necessary. #!/bin/bash read -p "Pausing for 5 seconds" -t 5 echo "Thanks for waiting."

What is the pause command in Linux?

pause() causes the calling process (or thread) to sleep until a signal is delivered that either terminates the process or causes the invocation of a signal-catching function.


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


And what about:

read -p "Press enter to continue"

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


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.