Start every script with the strict mode header: #!/usr/bin/env bash followed by set -euo pipefail on the next line.
-e exits on any command returning a non-zero status; -u treats unset variable references as errors; -o pipefail makes pipeline failures propagate the non-zero exit of any failed segment.
Install an ERR trap to log failures with context: trap 'echo "Error on line $LINENO: $BASH_COMMAND" >&2' ERR
Install an EXIT trap for cleanup that must run regardless: trap 'rm -f /tmp/myscript.lock' EXIT
Selectively disable strict mode for known-failing commands using: set +e; some_command_that_may_fail; set -e
Known gotchas
set -e does not trigger inside conditions (if some_command; then) or after ||; the command's non-zero exit is consumed by the control structure and does not abort the script.
Unset variables referenced inside double-quoted strings still trigger -u; use ${VAR:-default} to provide a fallback and avoid unintended errors.
trap handlers do not chain automatically; defining a second trap for the same signal overwrites the first — compose multiple actions within a single trap string or call a function.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp