EPOCHSECONDS
A bash 5 variable holding the current time as the number of seconds since 1 January 1970 UTC, known as Unix time.
In more detail
Reading it costs nothing, unlike running date +%s, which starts a new process each time. Subtracting two readings gives an elapsed time in whole seconds, handy for timing a step in a script.
Example
start=$EPOCHSECONDS; sleep 2; echo $((EPOCHSECONDS - start))Related terms
- BASH_VERSINFO — Built-in bash variables giving the running version: BASH_VERSION as a string and BASH_VERSINFO as an array of its parts.
- shell variable — A named value stored in the current shell, set with name=value and read back with $name.
Taught in
- Which Shell Am I In, And Getting Bash Five — Bash Scripting & Command Line Automation