Skip to content

Instantly share code, notes, and snippets.

@William-Lake
Created June 28, 2017 21:41
Show Gist options
  • Select an option

  • Save William-Lake/13db416601b877a6cf040e916be66191 to your computer and use it in GitHub Desktop.

Select an option

Save William-Lake/13db416601b877a6cf040e916be66191 to your computer and use it in GitHub Desktop.
Bash - Example of measuring elapsed time
#!/bin/bash
#############################################
# Determines how much time has elapsed.
#
# Takes advantage of the 'SECONDS' variable which is global environment variable in shell.
# 'SECONDS' is usually used by the environment to record how long it has been
# since a script was first executed.
#
# It's taken advantage of here to measure a length of time.
#############################################
# You can reset the 'SECONDS' variable whenever you want.
# This can be handy if you are using it as a timer, as resetting it will then reset your timer.
SECONDS=0
## Uncomment any of the lines below to get the elapsed time in different increments.
# Elapsed time in minutes
#ELAPSEDTIME=$((SECONDS / 60))
# Elapsed time in hours
#ELAPSEDTIME=$((SECONDS / 3600))
# Elapsed time in days
#ELAPSEDTIME=$((SECONDS / 86400))
echo "$ELAPSEDTIME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment