Skip to content

Instantly share code, notes, and snippets.

@matthewbednarski
Created September 5, 2014 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewbednarski/04686e071ddee118cfef to your computer and use it in GitHub Desktop.
Save matthewbednarski/04686e071ddee118cfef to your computer and use it in GitHub Desktop.
a countdown timer
#!/bin/bash
IFS=:
set -- $*
param1=0
param2=0
param3=0
if [ ${3} > 0 ]; then
param3=${3}
fi
if [ ${2} > 0 ]; then
param2=${2}
fi
if [ ${1} > 0 ]; then
param1=${1}
fi
secs=$(( (${param1} * 3600) + (${param2} * 60) + ${param3} ))
while [ $secs -gt 0 ]
do
sleep 1 &
printf "\r%02d:%02d:%02d" $((secs/3600)) $(( (secs/60)%60)) $((secs%60))
secs=$(( $secs - 1 ))
wait
done
printf "\r%02d:%02d:%02d" 0 0 0
paplay /usr/share/sounds/freedesktop/stereo/complete.oga
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment