18

I want to do something like following:

#!/bin/bash
command1
<pause for 30 seconds>
command2
exit

How can I do it?

Pandya
  • 34,843
  • 42
  • 126
  • 186

2 Answers2

28

You can use this in a terminal:

command1; sleep 30; command2

In your script:

#!/bin/bash
command1
sleep 30
command2
exit

Suffix for the sleep time:

  • s for seconds (the default)
  • m for minutes
  • h for hours
  • d for days
wjandrea
  • 14,109
  • 4
  • 48
  • 98
TuKsn
  • 4,330
  • 2
  • 26
  • 43
4

You can use read -t. E.g:

read -p "Continuing in 5 seconds..." -t 5
echo "Continuing..."

In your script:

command1
read -p 'Pausing for 30 seconds' -t 30
command2

Note that you can press Enter to bypass the timeout period.

wjandrea
  • 14,109
  • 4
  • 48
  • 98
Jose Rosa
  • 41
  • 1