Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

84.7. shellcheck-0.11.0

Static analysis for sh and bash scripts — quoting, word splitting and portability

Version 0.11.0, release 1
Shelf devtools — Debuggers, tracers, profilers, analysers, linters, language servers and developer utilities
Phase 41_system (System), 378 of 1047 in build order
Licence GPL-3.0-or-later
Homepage https://www.shellcheck.net
Build time 14.0 SBU
Installed size 14.1 MiB in 3 files
Recipe ports/core/devtools/shellcheck/kpkgbuild

About

ShellCheck reads sh and bash scripts and reports what the shell would accept and do wrong: an unquoted expansion that splits on spaces, a cd whose failure nothing checks, a variable set in a subshell and lost, a construct a POSIX sh does not have. Every build.sh in this tree is a bash script whose syntax testing/preflight.sh checks with bash -n; ShellCheck finds what parses and still goes wrong. It is written in Haskell, and the port builds it from Hackage’s ShellCheck source with ghc and cabal-install against a vendored set of Hackage packages.

Why it is in KDOS

The comment above it in script/phases/41_system/packages.d/devtools.txt:

preflight runs bash -n over the build.sh files and shfmt parses them; shellcheck ANALYSES them: the unquoted expansion that splits, the cd whose failure nothing checks, the variable read in a subshell and lost.

Sources

Dependencies

Depends on: ghc, cabal-install, gmp, libffi, lowdown.

Required by: no port names it.

Patches

build.sh applies these; kpkg applies nothing by itself.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install shellcheck'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/devtools/shellcheck.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/devtools/shellcheck
echo '81a72e9c195788301f38e4b2e250ab916cf3778993d428786bfb2fac2a847400  shellcheck-0.11.0.tar.gz' | sha256sum -c -
echo 'd20d1ed82e5560f113181a427e2e7df5a93ff1e356850040fdb0d7121c63c287  shellcheck-vendor-0.11.0.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/shellcheck
SRC=$SRC_ROOT/shellcheck-0.11.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf shellcheck-0.11.0.tar.gz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

tar xf "$PORT_SRC/$name-vendor-$version.tar.xz" -C "$SRC_ROOT"
cp "$SRC_ROOT/vendor/cabal.project.freeze" .
export CABAL_DIR="$SRC_ROOT/cabal"
mkdir -p "$CABAL_DIR"
printf 'repository hackage.haskell.org\n  url: file+noindex://%s\n' "$SRC_ROOT/vendor" \
	> "$CABAL_DIR/config"

cabal v2-install -j$KDOS_JOBS \
	--enable-split-sections \
	--enable-executable-stripping \
	--installdir="$PKG/usr/bin" --install-method=copy \
	exe:shellcheck

patch -p1 -i "$PORT_SRC/shellcheck-1-md-spaces.patch"
install -d "$PKG/usr/share/man/man1"
lowdown -s -Tman --out-no-smarty -o "$PKG/usr/share/man/man1/shellcheck.1" shellcheck.1.md

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/shellcheck, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf shellcheck-0.11.0-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/shellcheck, and runs the triggers its paths call for.

Contents

Installed programs: shellcheck.

Installed directories: /usr/share/licenses/shellcheck.

Short descriptions

shellcheck Shell script analysis tool

Notes

The vendor bundle comes from cabal freeze, run by ports/fetch in the fetch container with the GHC and cabal versions this tree builds; the freeze rides in the bundle and build.sh puts it back beside ShellCheck.cabal so the offline solve lands on exactly the packages that were downloaded. How the bundle is made and checked, and why the repository is configured under Hackage’s name with no --offline, is in The Haskell bundle.