Saturday, February 19, 2011

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

How do I pause for 5 seconds or 2 minutes in my bash shell script?

You need to use the sleep command to add delay for a specified amount of time. The syntax is as follows:

 
sleep NUMBER[SUFFIX]
 
Where SUFFIX may be:
  1. s for seconds (the default)
  2. m for minutes.
  3. h for hours.
  4. d for days.
To sleep for 5 seconds, use:

sleep 5

To sleep for 2 mintus, use:

sleep 2m

sleep Command Bash Script Example

  #!/bin/bash  
echo "Hi, I'm sleeping for 5 seconds..."  
sleep 5
echo "all Done."
 

No comments:

Post a Comment