running sh scripts through shellcheck

Martin Schwenke martin at
Fri Aug 11 08:44:02 UTC 2017

Hi Rowland,

On Fri, 11 Aug 2017 09:20:33 +0100, Rowland Penny via samba-technical
<samba-technical at> wrote:

> OK, I have got to ctdb/tests/complex/ where I
> have found this:
> echo "Getting MAC address associated with ${test_ip}..."
> releasing_mac=$(ip neigh show "$test_prefix" | awk '$4 == "lladdr" {print $5}')
> [ -n "$releasing_mac" ] || die "Couldn't get MAC address for ${test_prefix}"
> echo "MAC address is: ${releasing_mac}"
> So, who doesn't know that 'die' is a perl thing ?
> There doesn't seem to be a 'die' function.

There is a die() function in ctdb/tests/scripts/  It is
included somewhat indirectly.  ;-)

> The script is also a 'bash' script instead of a 'sh' script.

Yes, for historical reasons the CTDB integration tests are bash
scripts.  Nearly all other non-test scripts and unit test scripts are
"sh".  The "onnode" command is one exception because it is (nearly?)
impossible to write in POSIX shell.

Please don't spend too much time trying to get the CTDB tests to pass
shellcheck.  You'll go crazier than the person who wrote most of
the tests.  ;-)

One reason for the complexity of the CTDB test subsystem is that it
can be run in 3 ways:

* From within the git tree

* From within an unpacked tarball

* Installed on a test node - the "simple" and "complex" suites can be
  run against a real cluster

In ctdb/tests/shellcheck/ there is a little testsuite that runs all of
the non-test CTDB scripts through shellcheck.  There are a few
exceptions listed in ctdb/tests/shellcheck/scripts/ so that we
don't run all of the shellcheck "codes".

This can be run via:

  ctdb/tests/ shellcheck

You might notice that I posted some patches to the list today to
improve CTDB's shellcheck goodness.  If you're testing with a recent
version of shellcheck then you might need those patches.  My other post
comments on a test that fails due a regression in shellcheck - that
will be fixed in the next release of shellcheck.

Writing scripts is so much fun...  :-)

peace & happiness,

More information about the samba-technical mailing list