Interview Prep/Shell Scripting/Troubleshooting: strict mode, exit codes, pipelines and traps

`local release=$(curl -fsS "$API/latest")` fails with a 503, yet the function happily continues and deploys an empty release name.

IntermediateTroubleshootingTroubleshooting: strict mode, exit codes, pipelines and traps
Answer

Likely causes → local is a command, and its exit status (0) replaces the status of the command substitution. The same masking happens with export VAR=$(cmd), declare and readonly. ShellCheck reports it as SC2155.

Diagnose →

bash -c 'set -e; f(){ local x=$(false); echo "still running, x=[$x]"; }; f'
shellcheck deploy.sh | grep SC2155

Fix → Declare and assign separately, and validate the value:

local release
release=$(curl -fsS --max-time 10 "$API/latest")
[[ $release =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || die "bad release from API: '$release'"

Prevent → Keep ShellCheck at zero findings in CI; SC2155 alone catches this whole class of bug.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: strict mode, exit codes, pipelines and traps