An embeddable JavaScript engine written in Rust, providing a lexer, parser and interpreter with broad ECMAScript spec support.
mvdan/sh
A Go library and shfmt CLI for parsing, formatting, and interpreting shell scripts across POSIX, Bash, Zsh, and mksh.
- Stars
- 9,182
- Forks
- 465
- Open issues
- 78
- Last commit
- 4 days ago
What is it?
mvdan/sh is a shell parser, formatter, and interpreter written in pure Go. It covers POSIX Shell, Bash, Zsh, and mksh syntax, and parses scripts into a syntax tree that can be inspected or rewritten programmatically.
The project ships the shfmt command-line formatter, which applies a consistent style to shell scripts and can rewrite files in place. Packages are available for many Linux distributions, Homebrew, Scoop, Docker, and PyPI. Editor plugins for VS Code, Emacs, Vim and others wrap it.
Beyond formatting, the shell package offers helpers for splitting command lines, expanding variables and tildes, and glob matching, while the interp package runs scripts in Go without a system shell, including on Windows. Subshells are implemented with goroutines rather than real processes.
Key features
- 01Parses POSIX, Bash, Zsh, and mksh scripts into a syntax tree.
- 02Formats shell scripts with the shfmt CLI, including in-place rewriting.
- 03Runs scripts in Go without a system shell, including on Windows.
- 04Provides helpers for command-line splitting, quoting, variable expansion, and glob matching.
- 05Ships a Docker image and packages for many operating systems.
Use cases
- Enforcing a consistent style for shell scripts in a team repository via CI or pre-commit.
- Building Go tools that analyze or rewrite shell scripts programmatically.
- Embedding a sandboxed shell interpreter in a Go application.
- Formatting shell code in editors through existing shfmt plugins.
Quick start
- 1
Install the shfmt CLI with Go
go install mvdan.cc/sh/v3/cmd/shfmt@latest - 2
Format a shell script in place
shfmt -l -w script.sh
Things to know
- Requires Go 1.26 or later to install from source.
- Subshells run in goroutines, so real PIDs and file descriptors are not available in the interpreter.
- The `$((` and `((` ambiguity is not supported.
In collections
Topics
FAQ
- What is sh?
- A Go library and shfmt CLI for parsing, formatting, and interpreting shell scripts across POSIX, Bash, Zsh, and mksh. mvdan/sh is a shell parser, formatter, and interpreter written in pure Go. It covers POSIX Shell, Bash, Zsh, and mksh syntax, and parses scripts into a syntax tree that can be inspected or rewritten programmatically.
- Is sh free to use? What license does it have?
- sh is open source under the BSD-3-Clause license. Check the license terms before using it in commercial products.
- Is sh still maintained?
- Actively maintained. The last commit to sh was on Nov 3, 2026.
- What can I use sh for?
- Enforcing a consistent style for shell scripts in a team repository via CI or pre-commit. Building Go tools that analyze or rewrite shell scripts programmatically. Embedding a sandboxed shell interpreter in a Go application. Formatting shell code in editors through existing shfmt plugins.
- How do I install sh?
- Install the shfmt CLI with Go: go install mvdan.cc/sh/v3/cmd/shfmt@latest Format a shell script in place: shfmt -l -w script.sh
- Where can I get sh?
- The source code and installation instructions are on GitHub: https://github.com/mvdan/sh
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Go module for building colorful, styled console output with progress bars, tables, trees, charts, and interactive prompts.
A POSIX-compliant bash script for installing and switching between multiple Node.js versions per user and per shell.
Warp is an agentic development environment built out of the terminal, with a built-in coding agent or support for your own CLI agents.
A shell history replacement that stores commands in SQLite with context like exit code and duration, with optional end-to-end encrypted sync across machines.
A cross-platform prompt theme engine that renders customizable shell prompts for PowerShell, bash, zsh, fish, and more.