Apparently, all it takes to placate bashate
in this case is separation of the variable declaration from the subshell capture:
function func {
local var
var="$(...)"
...
}
This way you can check for errors that might have occured in the subshell:
var="$(...)"
status=$?
Initially I thought bashate
may have complained because the status var $?
was not handled, or that there might exist a method of capturing subshell output that I was not aware of. It was not, and I was not. Some related points however:
$?
can be captured in an atomic expression:
output=$(inner) || exit $?
see this answer by @grawity for similar forms.
$?
reports the status of the local
command rather than the subshell's exit status if used in a composite expression:
f() { local v=$(echo data; false); echo output:$v, status:$?; }
g() { local v; v=$(echo data; false); echo output:$v, status:$?; }
$ f # fooled by 'local' with inline initialization
output:data, status:0
$ g # a good one
output:data, status:1
see this answer by @ryenus for more information.
Finally, this answer among others in the thread detail some deficiencies in terms of portability and the style bashate
prescribes, which reinforces the notion that style guides are just tools that may or may not be the right tool for the job.