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
More on Functions, exit codes, strict mode and traps
How do you define a function, pass arguments and return a value?BeginnerWhat does `local` do, and what is dynamic scoping?AdvancedWhat are the conventional exit codes, and what do 126, 127, 130, 137 and 143 mean?BeginnerWhat does `set -e` do, and where does it NOT cause an exit?AdvancedExplain `set -euo pipefail` line by line, and add the `-E` flag.BeginnerWhy can `((count++))` kill a script under `set -e`?Intermediate