Skip to content

Instantly share code, notes, and snippets.

@jatinkrmalik
Last active February 8, 2017 08:15
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 jatinkrmalik/4875e654e8fac80ec7458608bfcd5dc2 to your computer and use it in GitHub Desktop.
Save jatinkrmalik/4875e654e8fac80ec7458608bfcd5dc2 to your computer and use it in GitHub Desktop.
A small script to implement countdown in bash
#!/bin/bash
# A small script to implement countdown in bash
seconds=200; # Set countdown time in seconds
date1=$((`date +%s` + $seconds)); # to get future time in seconds
# for asthetics
echo ""
# when present time is greater than or equal to the future time
while [ "$date1" -ge `date +%s` ];
do
# print the difference in time with -ne flag for input in same line
echo -ne "Tick tock $(date -u --date @$(($date1 - `date +%s` )) +%H:%M:%S)\r";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment