Interview Prep/Shell Scripting/Functions, exit codes, strict mode and traps

How do you time sections of a script and the script as a whole?

BeginnerConceptFunctions, exit codes, strict mode and traps
Answer
SECONDS=0
build; echo "build: ${SECONDS}s"

start=$EPOCHREALTIME              # Bash 5: microsecond precision
deploy
end=$EPOCHREALTIME
echo "deploy: $(awk "BEGIN {printf \"%.2f\", $end - $start}")s"

time ./deploy.sh                  # real, user, sys for the whole thing

Send timings to logs or a metrics endpoint so you can see deploys getting slower over weeks.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Functions, exit codes, strict mode and traps