Format shell scripts into a stable house style before review with shfmt
Normalize Bash, POSIX shell, and Zsh scripts before review or CI so style noise stops hiding the real changes.
Prerequisites
Go or packaged shfmt binary, shell script files, optional CI or pre-commit integration
Installation
Use the upstream install or setup path that matches your environment:
- go install mvdan.cc/sh/v3/cmd/shfmt@latest
- go install mvdan.cc/sh/v3/cmd/gosh@latest
- docker build -t my:tag -f cmd/shfmt/Dockerfile .
- docker run --rm -u "$(id -u):$(id -g)" -v "$PWD:/mnt" -w /mnt my:tag
Requirements and caveats from upstream:
- Supports [POSIX Shell], [Bash], [Zsh], and [mksh]. Requires Go 1.25 or later.
- Packages are available on [Alpine], [Arch], [Debian], [Docker], [Fedora], [FreeBSD],
Docker
Basic usage or getting-started notes:
To parse shell scripts, inspect them, and print them out,
see the syntax package.
For high-level operations like performing shell expansions on strings,
Source: https://github.com/mvdan/sh
Extracted from upstream docs: https://raw.githubusercontent.com/mvdan/sh/HEAD/README.md