CCL | Software | Download | Manuals | Forum | Papers
CCL Home

Research

Software Community Operations

Checks for sh-only syntax

We aim for all our shell-scripts to be POSIX compliant. This means that they should be written with sh-syntax only. In RedHat, the platform on which we develop, sh is a link to bash, and bash is not very good at enforcing POSIX compliance. The problem is that some Unix-like platforms do not install bash by default, and even if they do, they have sh implementations that are very strict at being POSIX compliant (e.g., dash in Debian, and /bin/sh in FreeBSD).

RedHat installs by default a script: /usr/bin/checkbashisms, that you can use to check for bash-only syntax in a sh script. If it is not installed, it is part of the devscripts tarball from Debian. Here is an example run:

$ checkbashisms work_queue/src/ec2_submit_workers
possible bashism in work_queue/src/ec2_submit_workers line 126 (declare):
declare -i inst_count
possible bashism in work_queue/src/ec2_submit_workers line 137 ('((' should be '$(('):
        ((inst_count=$inst_count+1))
zsh: exit 1     checkbashisms work_queue/src/ec2_submit_workers
The webpage dash as /bin/sh has a nice list of things to look for. Also, the following link has the official standard.