Samba and ShellCheck

Andreas Schneider asn at samba.org
Mon Aug 29 07:01:05 UTC 2022


On Tuesday, 23 August 2022 10:02:43 CEST Martin Schwenke via samba-technical 
wrote:
> Hi Andreas,
> 
> On Tue, 23 Aug 2022 07:50:24 +0200, Andreas Schneider via
> 
> samba-technical <samba-technical at lists.samba.org> wrote:
> > for Samba master we have ShellCheck with error level in place now. It will
> > check that our scripts are error free!
> 
> Yay!
> 
> That probably isn't true for CTDB, but we are gradually improving things.
> 
> > The next step would be to move ShellCheck to warning level and this will
> > be
> > quite some work.
> 
> Yep!
> 
> > But first we need to discuss something.
> > 
> > If I run ShellCheck in warning level:
> > 
> > ./script/check-shell-scripts.sh $(pwd) warning
> > 
> > The warning I see most of the time is:
> > 
> > warning: In POSIX sh, 'local' is undefined. [SC3043]
> 
> This is why I never use local in /bin/sh scripts.  It has never made it
> into POSIX.  I suspect the reason is that different shells implemented
> different semantics.  For example:
> 
>   local foo=$(example --command)
> 
> I think local in bash eats the exit code of the subshell.  Other shells
> may implement it differently.
> 
> I use an "excellent" convention for local variables in /bin/sh scripts,
> specially designed to reduce readability.  ;-)  I prefix any local
> variable with '_'.  However, it makes no semantic difference, it just
> acts as a hint.

Either we convert everything to this convention or we disable the shellcheck 
warning in those scripts. What do you prefer?

./script/check-shell-scripts.sh $(pwd) warning >shell.log 2>&1


Example to disable the warning:


 ctdb/tests/run_tests.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ctdb/tests/run_tests.sh b/ctdb/tests/run_tests.sh
index ff431f8831f..12e495e3dc0 100755
--- a/ctdb/tests/run_tests.sh
+++ b/ctdb/tests/run_tests.sh
@@ -1,4 +1,5 @@
 #!/usr/bin/env bash
+# shellcheck disable=SC3043
 
 usage() {
     cat <<EOF



-- 
Andreas Schneider                      asn at samba.org
Samba Team                             www.samba.org
GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D





More information about the samba-technical mailing list