There are various ways to show a countdown in your shell scripts.
First define your message:
Now clear the screen and display the message at row 10 and column 5 using tput:
Find out the length of string:
Calculate the next column:
Finally use a bash for loop to show countdown:
Here is a complete shell script:
msg="Purging cache please wait..."
Now clear the screen and display the message at row 10 and column 5 using tput:
clear
tput cup 10 5
Next you need to display the message:
echo -n "$msg"
Find out the length of string:
l=${#msg}
Calculate the next column:
l=$(( l+5 ))
Finally use a bash for loop to show countdown:
for i in {30..01}
do
tput cup 10 $l
echo -n "$i"
sleep 1
done
echo
Here is a complete shell script:
You can run it as follows:
./script.sh url1 url2
POSIX shell version
From this post:
It can be run as follows:
Sample session:
countdown "00:00:10" # 10 sec
countdown "00:00:30" # 30 sec
countdown "00:01:42" # 1 min 42 sec
Sample session:

No comments:
Post a Comment