Created
March 29, 2016 15:18
-
-
Save courtney-rosenthal/25f3306c166b91efce9e to your computer and use it in GitHub Desktop.
Display a text countdown for a given number of seconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# countdown - Display a text countdown for a given number of seconds. | |
# | |
# Chip Rosenthal | |
# [email protected] | |
USAGE="usage: $0 secs" | |
if [[ $# -ne 1 ]] ; then | |
echo "$USAGE" >&2 | |
exit 1 | |
fi | |
nsecs="$1" | |
if [[ ! $nsecs =~ ^[0-9]+$ ]] ; then | |
echo "$USAGE" >&2 | |
exit 1 | |
fi | |
tnow=`date "+%s"` | |
tstart=$(( tnow )) | |
tstop=$(( tstart + nsecs )) | |
while (( $tnow < $tstop )) ; do | |
tremain=$(( tstop - tnow )) | |
echo -e "\\r${tremain} ... \\c" | |
sleep 1 | |
tnow=`date "+%s"` | |
done | |
echo -e "\\rdone " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment