Skip to content

Instantly share code, notes, and snippets.

@krohne
Last active March 1, 2024 20:17
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save krohne/298c6393cf3dd6063b054dd297ba7714 to your computer and use it in GitHub Desktop.
Save krohne/298c6393cf3dd6063b054dd297ba7714 to your computer and use it in GitHub Desktop.
Countdown timer in bash shell script
#!/bin/bash
# $1 = # of seconds
# $@ = What to print after "Waiting n seconds"
countdown() {
secs=$1
shift
msg=$@
while [ $secs -gt 0 ]
do
printf "\r\033[KWaiting %.d seconds $msg" $((secs--))
sleep 1
done
echo
}
@krohne
Copy link
Author

krohne commented Jan 24, 2018

Usage:

#!/bin/bash
source countdown.sh
countdown 10 "before continuing"
echo "Continuing"
countdown 5 before the next thing
echo "The next thing"
countdown 3
echo "Done"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment