A short rant about #!/bin/sh

So… after about an hour of running a script which I quickly put together, this is the result:

core/automake 1.16.2-3
    /usr/share/automake-1.16/config.guess
    /usr/share/automake-1.16/install-sh
core/bash 5.0.018-1
    /usr/bin/bashbug
core/cronie 1.5.5-1
    /etc/cron.hourly/0anacron
extra/dkms 2.8.3-1
    /usr/lib/dkms/dkms_autoinstaller
core/gettext 0.21-1
    /usr/bin/autopoint
    /usr/bin/gettext.sh
    /usr/bin/gettextize
    /usr/share/gettext/projects/GNOME/team-address
    /usr/share/gettext/projects/KDE/team-address
extra/git 2.28.0-1
    /usr/lib/git-core/git-bisect
    /usr/lib/git-core/git-bisect--helper
    /usr/lib/git-core/git-web--browse
    /usr/share/git/git-jump/git-jump
    /usr/share/git/thunderbird-patch-inline/appp.sh
core/groff 1.22.4-3
    /usr/bin/eqn2graph
    /usr/bin/grap2graph
    /usr/bin/pdfroff
    /usr/bin/pic2graph
core/grub 2:2.04-8
    /usr/bin/grub-mkconfig
core/gzip 1.10-3
    /usr/bin/gzexe
    /usr/bin/zdiff
    /usr/bin/zgrep
core/hdparm 9.58-3
    /usr/bin/ultrabayd
extra/hwloc 2.2.0-1
    /usr/bin/hwloc-gather-topology
core/libtool 2.4.6+42+gb88cebd5-14
    /usr/bin/libtool
    /usr/bin/libtoolize
    /usr/bin/libtoolize
    /usr/share/libtool/build-aux/config.guess
    /usr/share/libtool/build-aux/install-sh
    /usr/share/libtool/build-aux/ltmain.sh
    /usr/share/libtool/configure
    /usr/share/libtool/configure.ac
community/lsb-release 1.4-18
    /usr/bin/lsb_release
extra/mjpegtools 2.1.0-5
    /usr/bin/lav2avi.sh
    /usr/bin/lav2mpeg
    /usr/bin/lavtc.sh
extra/mtools 4.0.24-1
    /usr/bin/tgz
    /usr/lib/resolvconf/dnsmasq
core/openresolv 3.11.0-1
    /usr/lib/resolvconf/named
    /usr/lib/resolvconf/pdns_recursor
    /usr/lib/resolvconf/pdnsd
    /usr/lib/resolvconf/unbound
extra/openvpn 2.4.9-2
    /usr/share/openvpn/contrib/pull-resolv-conf/client.down
    /usr/share/openvpn/contrib/pull-resolv-conf/client.up
community/os-prober 1.77-2
    /usr/bin/os-prober
    /usr/lib/linux-boot-probes/50mounted-tests
    /usr/lib/os-probes/50mounted-tests
    /usr/lib/os-probes/init/10filesystems
    /usr/lib/os-probes/mounted/05efi
extra/texlive-core 2020.55416-1
    /usr/share/texmf-dist/context/data/textadept/context/textadept-context.sh
    /usr/share/texmf-dist/web2c/mktexnam
    /usr/share/texmf-dist/web2c/mktexnam.opt
    /usr/share/tlpkg/installer/config.guess
extra/texlive-pictures 2020.55342-1
    /usr/share/texmf-dist/scripts/pgfplots/pgf2pdf.sh
core/usbutils 012-2
    /usr/bin/usb-devices
extra/xdg-utils 1.1.3+19+g9816ebb-1
    /usr/bin/xdg-desktop-icon
    /usr/bin/xdg-desktop-menu
    /usr/bin/xdg-email
    /usr/bin/xdg-icon-resource
    /usr/bin/xdg-mime
    /usr/bin/xdg-open
    /usr/bin/xdg-screensaver
    /usr/bin/xdg-settings
core/xz 5.2.5-1
    /usr/bin/xzdiff

There are some 23 packages on my system, many of these from the “core” repo, which ship some 65 scripts with which are identified as POSIX scripts by the file command (and use sh as the command interpreter), but are identified by the checkbashisms utility to contain POSIX non-compliant commands.

In total, some 823 scripts were checked, so the percentage of offending scripts was around 7.9%.

Ironically, a script from the package bash which is used to report bugs in Bash, is one of those offending scripts.

If anyone else wants to do a similar analysis, I’d be very interested in your results.

3 Likes