Last active
December 10, 2015 18:58
-
-
Save esoupy/4478235 to your computer and use it in GitHub Desktop.
bash script Timer function. Creates a stopwatch and displays the time duration between calls.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Timer Function - displays the timed duration between start and stop ## | |
# example: | |
# Timer start | |
# Script_Cmds | |
# Timer stop | |
Timer() { | |
## Set a timer to display duration ## | |
# Usage: Timer [start|stop] | |
Tcmd=$1 | |
case $Tcmd in | |
start|Start|START) _StartSecs=$(date +%s) | |
;; | |
stop|Stop|STOP) _StopSecs=$(date +%s) | |
[[ ! $_StartSecs ]] && echo "[Internal Error] $FUNCNAME did not record a start." && return | |
_DiffSecs=$(($_StopSecs-$_StartSecs)) | |
TimeLapse=$(date -u -d@"$_DiffSecs" +'%-Hh%-Mm%-Ss') | |
echo "Timer: $TimeLapse" | |
;; | |
*) echo "[Internal Error] $FUNCNAME: Unknown arg '$Tcmd'" | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment