Friday, June 19, 2009

Countdown shell (bash) script


function countdown () {
a=$1
while [ $a -gt 0 ]; do
echo $a;
a=$(($a-1));
done
}
for i in `countdown 10`; do echo $i; sleep 0.1; done

2 comments:

nueces said...

You can do the same using the commnand 'seq'

for i in $(seq 10 -1 1);do echo $i && sleep 0.2; done

nueces said...

or..

for i in {10..1};do echo $i && sleep 0.2; done