Skip to content

Instantly share code, notes, and snippets.

@putnamhill
Created July 31, 2013 20:04
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 putnamhill/6125638 to your computer and use it in GitHub Desktop.
Save putnamhill/6125638 to your computer and use it in GitHub Desktop.
A simple bash stop watch.
#!/bin/bash
START=$(date +%s)
read -s -n1 -p $'Press a key when done.\n'
ELAPSED_SECONDS=$(bc <<< "scale=10; ($(date +%s) - $START)")
if [ $ELAPSED_SECONDS -gt 60 ]; then
ELAPSED_MINUTES=$((ELAPSED_SECONDS / 60))
ELAPSED_SECONDS=$((ELAPSED_SECONDS - ELAPSED_MINUTES * 60))
echo -n "$ELAPSED_MINUTES minutes "
fi
echo "$ELAPSED_SECONDS seconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment