Remove (some) bashisms from the test scripts

Martin Schwenke martin at meltin.net
Fri Dec 22 13:23:41 UTC 2017


On Fri, 22 Dec 2017 10:05:50 +0100, "Timur I. Bakeyev via
samba-technical" <samba-technical at lists.samba.org> wrote:

> On Fri, Dec 22, 2017 at 9:35 AM, Uri Simchoni <uri at samba.org> wrote:
> 
> > On 12/22/2017 03:58 AM, Timur I. Bakeyev via samba-technical wrote:  
> > > Yet another fixes to make self-test work out of the box on FreeBSD.
> > >
> > > Despite having '#!/bin/sh' in the test shell scripts there are some
> > > bashisms present,
> > > that make FreeBSD sh croak.
> > >
> > > I've run Debian's 'checkbashisms' script against test scripts and tried  
> > to  
> > > address most of it's (reasonable) warnings.
> > >
> > > Also, one failing test spotted the place where direct call to the
> > > 'ldbsearch' wasn't replaced with the configurable path.  
> >
> > We have another possible path - mark scripts which use bash syntax as
> > #!/bin/bash (or even "standardize" on bash).
> >
> > There are tests which are truly bash-specific - I might have introduced
> > the first one and the bash dependency was discussed on the list (using
> > bash arrays - the shadow_copy2 test). I also (hours before this patch
> > submitted :)) updated the Samba wiki about the need to have bash to run
> > tests.
> >
> > I personally find the bash syntax less error prone ([[ vs [ mostly) and
> > would prefer to keep the "bashisms" as bash scripts instead of shell
> > scripts, but I can see how there can be strong opinions to the other
> > side, so we should first solicit input on that and decide on the general
> > direction.
> >  
> 
> Well, bash is evil and should be avoided, whenever it's possible, IMHO.
> In general if you care about any kind of portability it should be avoided.

I tend to agree.  I try to aim for POSIX compliant shell.  While bash
is very tempting there are very few features that are really needed.

> Unfortunately, we can't dictate here, so have to follow the path that Samba
> project will chose, but if you going to introduce such a dependency, please,
> remember that bash for FreeBSD is a foreign program, so it'll be in
> /usr/local/bin/bash. Hence you'll have to apply the same magic you used
> for the Perl.
> 
> And, as of the given patch - the bashisms we see are, clearly results of the
> inaccurate programming, where POSIX shell was meant, but some foreign
> elements did slip into. There isn't anything Bash specific in those
> scripts, just
> some syntax elements wrongly used. And, being prefixed with #!/bin/sh they
> demand the wrong guy to do the job.

For CTDB (ctdb/ subdirectory) we have aimed for POSIX compliant shell
as much as possible.  At the moment the only bash scripts are the
integration tests.  All the run-time scripts (except onnode) and unit
tests are all POSIX.  All of the run-time scripts are run through
shellcheck (if installed) in a unit test suite.  We just don't have the
time to do the same for all of the test scripts too.

However, for IP failover we depend on the Linux iproute2 "ip" command,
so that is unlikely to be portable anyway.  This is about to be
rewritten so it might be possible to contain the Linux-specific parts
fairly well so that people can write non-Linux alternatives.  That
remains to be seen...

peace & happiness,
martin



More information about the samba-technical mailing list