Samba and ShellCheck
Martin Schwenke
martin at meltin.net
Tue Aug 23 08:02:43 UTC 2022
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.
> Why do do we use POSIX shell (#/bin/sh) for the majority of our tests (we also
> have scripts with #!/bin/bash)?
For portability. I would encourage anyone writing scripts that do not
need bash features to use /bin/sh instead.
In CTDB we have switched our bash scripts (we definitely have some)
to use
#!/usr/bin/env bash
so they have a chance of working on platforms without /bin/bash.
peace & happiness,
martin
More information about the samba-technical
mailing list