Skip to content

Instantly share code, notes, and snippets.

@SebastianGrans
Created May 17, 2016 13:26
Show Gist options
  • Save SebastianGrans/7b6368624352795a8abb023ed0f520fd to your computer and use it in GitHub Desktop.
Save SebastianGrans/7b6368624352795a8abb023ed0f520fd to your computer and use it in GitHub Desktop.
Bash script that gives you a running clock in the terminal
#!/bin/bash
# The clock function I got from here:
# http://www.linuxandlife.com/2012/08/how-to-create-continuous-digital-clock.html
#
# And then I wanted a script that would terminate on 'any key'
# http://stackoverflow.com/questions/5297638/bash-how-to-end-infinite-loop-with-any-key-pressed
#
if [ -t 0 ]; then stty -echo -icanon -icrnl time 0 min 0; fi
count=0
keypress=''
while [ "x$keypress" = "x" ]; do
echo -e \\b\\b\\b\\b\\b\\b\\b\\b`date +%T`\\c
sleep 1
keypress="`cat -v`"
done
if [ -t 0 ]; then stty sane; fi
echo ""
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment