Skip to content

Instantly share code, notes, and snippets.

@jmar71n
Created April 28, 2010 17:41
Show Gist options
  • Save jmar71n/382430 to your computer and use it in GitHub Desktop.
Save jmar71n/382430 to your computer and use it in GitHub Desktop.
bash timer script
#!/bin/sh
# Section to timed between START an FINISH...
START=$SECONDS
echo "sleep 30s"
sleep 30s
FINISH=$SECONDS
timer ()
{
hrs="$((($FINISH - $START)/3600))hrs"
min="$(((($FINISH - $START)/60)%60))min"
sec="$((($FINISH - $START)%60))sec"
if [[ $(($FINISH - $START)) -gt 3600 ]]; then echo "$hrs, $min, $sec"
elif [[ $(($FINISH - $START)) -gt 60 ]]; then echo "$min, $sec"
else echo "$sec"
fi
}
echo -n "Elapsed time: "; timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment