A shell parser, formatter, and interpreter. Supports POSIX Shell, Bash, and mksh. Requires Go 1.21 or later.
To parse shell scripts, inspect them, and print them out, see the syntax examples.
For high-level operations like performing shell expansions on strings, see the shell examples.
go install mvdan.cc/sh/v3/cmd/shfmt@latest
shfmt
formats shell programs. See canonical.sh for a
quick look at its default style. For example:
shfmt -l -w script.sh
For more information, see its manpage, which can be viewed directly as Markdown or rendered with scdoc.
Packages are available on Alpine, Arch, Debian, Docker, Fedora, FreeBSD, Homebrew, MacPorts, NixOS, OpenSUSE, Scoop, Snapcraft, Void and webi.