← Software

shfmt

A formatter for shell scripts.

shfmt parses POSIX shell, Bash, and mksh scripts and re-emits them with consistent indentation, line breaks, and quoting normalisation. Combined with ShellCheck, it gives shell scripts the kind of formatter-plus-linter pairing that JavaScript has with Prettier and ESLint.

Daniel Martí writes shfmt in Go as part of the mvdan.cc/sh shell parsing library, which is also used by other tools that need to programmatically inspect shell scripts. The same library underlies the bash AST viewer in some IDE plugins.

shfmt is widely used in CI pipelines as a formatter check, either on its own or via pre-commit hooks. Editor integrations exist for VS Code, Vim/Neovim, Emacs, Sublime Text, and several others, which makes the formatting effectively automatic during day-to-day shell-script editing.

License: BSD-3-Clause

Category: Developer tools

Website: https://github.com/mvdan/sh

Install

go install mvdan.cc/sh/v3/cmd/shfmt@latest
Or:
  Debian/Ubuntu: sudo apt install shfmt
  Arch:          sudo pacman -S shfmt
  macOS:         brew install shfmt

Authors

  • Daniel Martí (creator)
PreviousShellCheck NextShotcut

This site is currently in Beta. Contact: Chris Paton

Textbook of AI · Textbook of Usability · Textbook of Digital Health

Auckland Maths and Science Tutoring