Linux / UNIX: Bash Script Sleep or Delay a Specified Amount of Time

To sleep or delay a specified amount of time in a bash script, you can use the sleep command. This command takes the number of seconds to wait as an argument. For example, to sleep for 5 seconds:

#!/bin/bash

# Sleep for 5 seconds
sleep 5

In some cases, you might need to sleep for a longer duration, in which case, you can specify the number of minutes or hours by converting them to seconds.

For example, to sleep for 5 minutes:

#!/bin/bash

# Sleep for 5 minutes
sleep $((5 * 60))

Or, to sleep for 1 hour:

#!/bin/bash

# Sleep for 1 hour
sleep $((60 * 60))

Leave a Comment