From: Michal Privoznik <mprivozn@redhat.com> As mentioned in the previous commit, the following function doesn't echo '1' but '0': func() { local var=$(false) echo $? } It's explained here [1]. Since this kind of error is not easy to catch a new syntax-check rule is introduced. To avoid having multiline grep and match only those patterns where '$?' is examined, let's keep the rule simple and forbid all local declarations with subshell. 1: https://www.shellcheck.net/wiki/SC2155 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- build-aux/syntax-check.mk | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index f605c9b0e3..ff44dfa2fe 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -394,6 +394,12 @@ sc_prohibit_g_autofree_const: halt='‘g_autofree’ discards ‘const’ qualifier from pointer target type' \ $(_sc_search_regexp) +sc_prohibit_local_with_subshell: + @prohibit='local [a-zA-Z]+="?\$$\(.+' \ + in_vc_files='\.sh(\.in)?$$' \ + halt='local variable with subshell does not do what you think it does' \ + $(_sc_search_regexp) + # Many of the function names below came from this filter: # git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$' \ -- 2.52.0