🍺 BREW Explorer

← all formulae

shfmt

brew install shfmt v3.13.1 BSD-3-Clause

Go-based formatter and parser for POSIX shell, Bash, Zsh, and mksh scripts.

Why you might care

Automatically standardizes shell script formatting across projects with consistent style rules, similar to gofmt for Go. Supports multiple shell dialects and can parse/interpret scripts, not just format them. Single binary with no external dependencies makes it ideal for CI/CD pipelines and pre-commit hooks.

Categories

Alternatives

shfmt shellcheck beautysh
4.5k
30-day installs · #651
24.0k
90-day · #454
59.7k
365-day · #591
8.8k
★ GitHub stars · updated 7d ago

Build dependencies

GitHub topics

bash beautify formatter go interpreter mksh parser posix shell shfmt zsh

Links

Blurb generated by claude-haiku-4-5 on today.

Raw metadata
{
  "aliases": [],
  "alternatives": [
    "shfmt",
    "shellcheck",
    "beautysh"
  ],
  "build_dependencies": [
    "go",
    "scdoc"
  ],
  "categories": [
    "formatter",
    "parser",
    "shell"
  ],
  "caveats": null,
  "conflicts_with": [],
  "dependencies": [],
  "deprecated": 0,
  "deprecation_reason": null,
  "desc": "Autoformat shell script source code",
  "disable_reason": null,
  "disabled": 0,
  "enrichment_fetched_at": "2026-06-20T23:41:00+00:00",
  "first_seen": "2026-06-20T23:34:18+00:00",
  "full_name": "shfmt",
  "github_default_branch": "master",
  "github_last_commit_at": "2026-06-13T07:55:24Z",
  "github_readme_excerpt": "# sh\n\n[![Go Reference](https://pkg.go.dev/badge/mvdan.cc/sh/v3.svg)](https://pkg.go.dev/mvdan.cc/sh/v3)\n\nA shell parser, formatter, and interpreter.\nSupports [POSIX Shell], [Bash], [Zsh], and [mksh]. Requires Go 1.25 or later.\n\n### Quick start\n\nTo parse shell scripts, inspect them, and print them out,\nsee the [syntax package](https://pkg.go.dev/mvdan.cc/sh/v3/syntax).\n\nFor high-level operations like performing shell expansions on strings,\nsee the [shell package](https://pkg.go.dev/mvdan.cc/sh/v3/shell).\n\nTo interpret or run shell scripts,\nsee the [interp package](https://pkg.go.dev/mvdan.cc/sh/v3/interp).\n\n### shfmt\n\n\tgo install mvdan.cc/sh/v3/cmd/shfmt@latest\n\n`shfmt` formats shell programs. See [canonical.sh](syntax/canonical.sh) for a\nquick look at its default style. For example:\n\n\tshfmt -l -w script.sh\n\nFor more information, see [its manpage](cmd/shfmt/shfmt.1.scd), which can be\nviewed directly as Markdown or rendered with [scdoc].\n\nPackages are available on [Alpine], [Arch], [Debian], [Docker], [Fedora], [FreeBSD],\n[Homebrew], [MacPorts], [NixOS], [OpenSUSE], [Scoop], [Snapcraft], [Void] and [webi].\n\n### gosh\n\n\tgo install mvdan.cc/sh/v3/cmd/gosh@latest\n\nProof of concept shell that uses the `interp` package.\n\n### Fuzzing\n\nWe use Go\u0027s native fuzzing support. For instance:\n\n\tcd syntax\n\tgo test -run=- -fuzz=ParsePrint\n\n### Caveats\n\n* When indexing Bash associative arrays, always use quotes. The static parser\n  will otherwise have to assume that the index is an arithmetic expression.\n\n```sh\n$ echo \u0027${array[spaced string]}\u0027 | shfmt\n\u003cstandard input\u003e:1:16: not a valid arithmetic operator: `string`\n$ echo \u0027${array[weird!key]}\u0027 | shfmt\n\u003cstandard input\u003e:1:8: reached `!` without matching `[` with `]`\n$ echo \u0027${array[dash-string]}\u0027 | shfmt\n${array[dash - string]}\n```\n\n* `$((` and `((` ambiguity is not supported. Backtracking would complicate the\n  parser and make streaming support via `io.Reader` impossible. The POSIX spec\n  recommends to [space the operands][posix-ambiguit",
  "github_repo": "mvdan/sh",
  "github_stars": 8835,
  "github_topics": [
    "bash",
    "beautify",
    "formatter",
    "go",
    "interpreter",
    "mksh",
    "parser",
    "posix",
    "shell",
    "shfmt",
    "zsh"
  ],
  "homepage": "https://github.com/mvdan/sh",
  "homepage_og_description": null,
  "homepage_og_image": null,
  "homepage_title": null,
  "installs_30d": 4475,
  "installs_365d": 59660,
  "installs_90d": 23995,
  "keg_only": 0,
  "keg_only_reason": null,
  "last_seen": "2026-06-20T23:34:18+00:00",
  "license": "BSD-3-Clause",
  "llm_generated_at": "2026-06-20T23:46:10+00:00",
  "llm_model": "claude-haiku-4-5",
  "name": "shfmt",
  "oldnames": [],
  "one_liner": "Go-based formatter and parser for POSIX shell, Bash, Zsh, and mksh scripts.",
  "optional_dependencies": [],
  "rank_30d": 651,
  "rank_365d": 591,
  "rank_90d": 454,
  "raw_hash": "72121eb3ceca789e",
  "recommended_dependencies": [],
  "revision": 0,
  "ruby_source_path": "Formula/s/shfmt.rb",
  "tap": "homebrew/core",
  "test_dependencies": [],
  "uses_from_macos": [],
  "version_head": "HEAD",
  "version_stable": "3.13.1",
  "versioned_formulae": [],
  "why_use_this": "Automatically standardizes shell script formatting across projects with consistent style rules, similar to gofmt for Go. Supports multiple shell dialects and can parse/interpret scripts, not just format them. Single binary with no external dependencies makes it ideal for CI/CD pipelines and pre-commit hooks."
}