Running bash script tests on multiple versions of bash

It appears that bash is not one of the supported languages for use in a matrix.

At first I tried building by own version from source, but was not particularly fast.

I then tried using the official docker versions of bash and this seemed to work.

This is the resulting config file:

language: bash

env:
  - BASH=latest
  - BASH=5.0.3
  - BASH=4.4.23
  - BASH=4.3.48
  - BASH=4.2.53
before_script:
  - docker pull bash:$BASH
  - docker run bash:$BASH --version
script:
  - docker run -v $PWD:/bash bash:$BASH bash/example/array.sh
  - docker run -v $PWD:/bash bash:$BASH bash/example/human.sh
  - docker run -v $PWD:/bash bash:$BASH bash/example/string.sh
  - docker run -v $PWD:/bash bash:$BASH bash/example/testing.sh
  - docker run -v $PWD:/bash bash:$BASH bash/example/trycatch.sh

To see this running:
https://travis-ci.com/mmcc007/bash-oo-framework/builds/105794384

This has limitations as it forces the script to run in a very lightweight docker container that for example does not have the ‘cd’ command.

Is there a better way to do script testing against multiple versions of bash?

Ubuntu provides only one version of Bash available via its APT packages (e.g., https://packages.ubuntu.com/trusty/bash or https://packages.ubuntu.com/xenial/bash). As such, our options are limited, and using Docker images seems like a reasonable solution.

This does not make sense to me. cd is a built-in function of bash, so it should be available no matter where you execute bash.

I had a problem doing a ‘cd’ in the bash container for some reason (said it could not find it… probably related to way I am calling it). Later realized, and you are correct, ‘cd’ is a bash reserved word.
(Still haven’t found the problem, but have a workaround)

I was hoping there might be a general solution for testing language versions that I was not aware of. If there is no obvious better way, then I’ll stick with this. Can always extend the container if needed.

Thnx!

Imprint