Web Analytics

Debugging

Advanced~25 min read

Enable tracing, fail fast on errors, and detect unset variables to catch bugs early.

Tracing and Strict Modes

Output
Click Run to execute your code
Note: Prefer enabling options in subshells to avoid affecting the whole script unintentionally.
Pro Tip: Add trace prefixes with PS4='+ :: ' for clearer set -x output.
Caution: set -e has edge cases with pipelines and subshells. Consider explicit checks.

Common Mistakes

1) Assuming -e covers all errors

Check exit codes or use pipefail for pipelines.

2) Tracing secrets

Avoid printing sensitive data under xtrace in CI logs.

Exercise: Safer Pipeline

Task: Enable set -o pipefail and demonstrate a failing pipeline that correctly returns non-zero.

Output
Click Run to execute your code
Show Solution
set -o pipefail; false | true; echo $? # -> 1

Summary

  • Trace with -x.
  • Fail fast with -e.
  • Detect typos with -u; use pipefail for pipelines.

What's Next?

Generate sequences and templated names via Brace Expansion.