Created
June 28, 2017 21:41
-
-
Save William-Lake/13db416601b877a6cf040e916be66191 to your computer and use it in GitHub Desktop.
Bash - Example of measuring elapsed time
This file contains hidden or 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 | |
| ############################################# | |
| # 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