Countdown in a Shell Script

Tuesday's still the weekend right? ;-)

Anyhow here's a little code snippet for inserting a count down into a shell script. Simply put this before whatever you want to delay, and then make sure that the first argument you pass to the script is the number of seconds to wait. An example of the sort of thing you might want to use this for is taking screenshots.

#!/bin/bash
for i in  $(seq $1  -1  1); do
    echo  $i
    sleep  1
done
echo 0
$2

For example if you run it like this: ./countdown.sh 5 "echo Blast Off" you'll get the following output:

$ ./countdown.sh 5 "echo Blast Off"
5
4
3
2
1
0
Blast Off
$
Categories: Computers, Scripting, Linux
Date: 2009-04-07 23:03:53, 15 years and 262 days ago

Leave reply

No html allowed in reply

Notify me of follow-up comments via email.