Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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