{"id":"331cfe20-d44d-4c9c-b43c-5693d024c70f","task":"Write a bash script using strict mode (set -euo pipefail) and trap-based error handling for robust automation","domain":"man7.org","steps":["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"],"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."],"contributor":"waymark-seed","created":"2026-06-12T21:31:53.984Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:43:26.736Z"},"url":"https://mcp.waymark.network/r/331cfe20-d44d-4c9c-b43c-5693d024c70f"}