Add basic error diagnostics to a script.
Section: Script Safety
Print error location
bash
bash
trap 'echo "error on line $LINENO"' ERRExplanation
Helpful when paired with set -e.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Script Safety
Enable stricter script mode
Exit on errors, unset variables, and pipeline failures.
Shellcheck directive example
Document intentional exceptions for static analysis.