On a Monday in 2026, Michal Privoznik via Devel wrote:
From: Michal Privoznik <[email protected]>In shell, the following function doesn't echo '1' but '0': func() { local var=$(false) echo $? } This is because '$?' does not refer to 'false' but 'local'. The bash_builtins(1) manpage explains it well. And it also mentions other commands behaving the same: export, declare and readonly. Since it is really easy to miss this pattern, introduce a syntax-check rule. Mind you, the following patter (which passes
*pattern Jano
the rule) does check for the subshell exit code:
func() {
local var
var=$(false)
echo $?
}
Signed-off-by: Michal Privoznik <[email protected]>
---
build-aux/syntax-check.mk | 11 +++++++++++
1 file changed, 11 insertions(+)
signature.asc
Description: PGP signature
