Interview Prep/Shell Scripting/Variables, quoting and expansions

What do `SECONDS`, `LINENO`, `FUNCNAME`, `BASH_SOURCE` and `PIPESTATUS` provide?

IntermediateConceptVariables, quoting and expansions
Answer
  • SECONDS: seconds since the shell started; reset with SECONDS=0 to time a step.
  • LINENO: current line number, ideal in error messages.
  • FUNCNAME: array of the current call stack of function names.
  • BASH_SOURCE: array of source files matching FUNCNAME.
  • PIPESTATUS: array of exit codes of each command in the last pipeline.
SECONDS=0; rsync -a src/ dst/; echo "rsync took ${SECONDS}s"
die() { echo "ERROR ${BASH_SOURCE[1]}:${BASH_LINENO[0]} in ${FUNCNAME[1]}: $*" >&2; exit 1; }
All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Variables, quoting and expansions