Skip to content

Instantly share code, notes, and snippets.

@taiansu
Created September 22, 2013 16:06
Show Gist options
  • Save taiansu/6661354 to your computer and use it in GitHub Desktop.
Save taiansu/6661354 to your computer and use it in GitHub Desktop.
count down in shell
function countdown
{
local SECONDS=$1
local START=$(date +%s)
local END=$((START + SECONDS))
local CUR=$START
while [[ $CUR -lt $END ]]
do
CUR=$(date +%s)
LEFT=$((END-CUR))
printf "\r%01d" \
$((LEFT%60))
sleep 1
done
echo " "
}
countdown '5'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment