The container is an Alpine Linux (edge) container with the following tools:
- posh shell (this is the default)
- dash shell
rlwrap to offer readline support for either of the above shells (
rlwrap poshis the default command if none specified)
- checkbashisms for rooting out Bash-specific idiosyncrasies in scripts
- shellcheck for shell script linting
See the "Writing Bash Scripts that are not only Bash" for explanation and usage of the above.
(Podman also works fine in any of the examples below.)
First, pull the image:
docker pull docker.io/bowmanjd/posix-playground
To launch posh: Policy-compliant Ordinary SHell with readline support:
docker run -it -v "$PWD:/work" posix-playground
To instead launch dash shell with readline support:
docker run -it -v "$PWD:/work" posix-playground rlwrap dash
rlwrap, line editing in either of these shells is impossible, making experimentation rather painful. Using
rlwrap is recommended.)
To check a
helloworld.sh shell script in the current directory for "bashisms" (make sure the first line, the "shebang", reads
docker run -it -v "$PWD:/work" posix-playground checkbashisms helloworld.sh
To check a
helloworld.sh shell script in the current directory for a variety of gotchas:
docker run -it -v "$PWD:/work" posix-playground shellcheck helloworld.sh
To simply run a script from the current directory, using posh:
docker run -it -v "$PWD:/work" posix-playground posh myscript.sh
Of the tools included in the image, posh is the winner for me. It is not available on every distro, so having a container available is quite convenient.
Posh is also quite strict, and this is the point. It does not have any syntactic sugar to make it more Bash-like. I feel quite reassured when a script runs correctly in posh.
If you have other tools to recommend, or want to reflect on your experiences with this container image, feel free to post in the comments!