Interview Prep/Shell Scripting/Functions, exit codes, strict mode and traps

Why is `local out=$(cmd)` a problem under `set -e`?

AdvancedConceptFunctions, exit codes, strict mode and traps
Answer

The exit status of local out=$(cmd) is the status of local (0), not of cmd, so failures are silently ignored even with set -e. The same applies to export x=$(cmd) and readonly x=$(cmd). ShellCheck reports SC2155.

local out
out=$(curl -fsS "$url")      # now set -e (or || return) sees curl's status
All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Functions, exit codes, strict mode and traps