What do `SECONDS`, `LINENO`, `FUNCNAME`, `BASH_SOURCE` and `PIPESTATUS` provide?
IntermediateConceptVariables, quoting and expansions
Answer
SECONDS: seconds since the shell started; reset withSECONDS=0to 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 matchingFUNCNAME.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; }
More on Variables, quoting and expansions
What are the rules for assigning variables in Bash?BeginnerWhat is the difference between single quotes, double quotes and `$'...'`?BeginnerWhy should you almost always quote variable expansions? Show what goes wrong.BeginnerExplain the difference between `"$@"`, `"$*"`, `$@` and `$*`.IntermediateWhat do `${var:-default}`, `${var:=default}`, `${var:+alt}` and `${var:?msg}` do?IntermediateHow do you strip prefixes and suffixes with parameter expansion?Intermediate