A stopwatch in bash

Is it possible to implement a stopwatch in bash? Here is my try:

https://github.com/jschnasse/stopwatch/blob/master/stopwatch

The script uses some interesting features like:

  1.  read -s -t.1 -n1 c to read exactly one character (-n1) into a variable c only waiting 0.1 seconds for user input.
  2. sleep .1 to delay further processing for 0.1 seconds
  3. secs=$(printf "%1d\n" ${input: 0 : -9})Create a digit from all but the last 9 characters lead by a zero if string is empty. This is used to separate seconds from a nano seconds. 

Leave a Reply