# mvdan/sh

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/mvdan-sh).**

8,825 stars · 414 forks · Go · BSD-3-Clause

## Links

- GitHub: https://github.com/mvdan/sh
- Homepage: https://pkg.go.dev/mvdan.cc/sh/v3
- awesome-repositories: https://awesome-repositories.com/repository/mvdan-sh.md

## Description

This project is a POSIX shell toolset providing utilities for parsing, formatting, interpreting, and validating shell scripts. It includes a parser that converts Bash and Zsh source code into structured syntax trees, a formatter for standardizing script layout, and a runtime interpreter for executing shell commands and script logic.

The toolset supports dialect-aware parsing to handle multiple shell language specifications. It provides capabilities for static analysis, allowing shell source code to be converted into structured data for external manipulation or validation against specific dialect rules.

Additional capabilities include resolving variable and glob expansions, verifying UTF-8 encoding, and scanning directory hierarchies to discover shell script files. The system can also serialize internal syntax trees to and from typed JSON for state restoration and external analysis.

## Tags

### Development Tools & Productivity

- [Parsers](https://awesome-repositories.com/f/development-tools-productivity/shell-scripting-tools/parsers.md) — Provides a dialect-aware parser that converts Bash and Zsh source code into structured syntax trees for static analysis. ([source](https://github.com/mvdan/sh#readme))
- [Script Formatters](https://awesome-repositories.com/f/development-tools-productivity/script-formatters.md) — Standardizes the layout and style of shell scripts to ensure consistent code formatting.
- [Shell Script Parsers](https://awesome-repositories.com/f/development-tools-productivity/shell-script-parsers.md) — Converts Bash and Zsh source code into structured syntax trees for static analysis.
- [Shell Scripting Linters](https://awesome-repositories.com/f/development-tools-productivity/shell-scripting-linters.md) — Converts shell source code into structured data for static analysis and logic manipulation.
- [Shell Scripting Tools](https://awesome-repositories.com/f/development-tools-productivity/shell-scripting-tools.md) — Standardizes the layout of shell scripts using consistent style rules to improve readability. ([source](https://github.com/mvdan/sh#readme))

### Operating Systems & Systems Programming

- [POSIX Shell Utilities](https://awesome-repositories.com/f/operating-systems-systems-programming/posix-shell-utilities.md) — Provides a comprehensive toolset of utilities for validating, expanding, and manipulating POSIX shell scripts.

### Part of an Awesome List

- [Code Formatting and Style](https://awesome-repositories.com/f/awesome-lists/devtools/code-formatting-and-style.md) — Standardizes the layout and style of shell scripts by reconstructing source code from a syntax tree.
- [Shell-Native Substitutions](https://awesome-repositories.com/f/awesome-lists/devtools/text-and-string-utilities/shell-native-substitutions.md) — Resolves variables and glob patterns within strings according to standard shell rules. ([source](https://github.com/mvdan/sh#readme))
- [Shell Script Development](https://awesome-repositories.com/f/awesome-lists/devtools/shell-script-development.md) — Formatter for cleaning up and standardizing shell code.

### Mobile Development

- [Script Execution Environments](https://awesome-repositories.com/f/mobile-development/mobile-capabilities/script-execution-environments.md) — Provides a runtime environment that executes shell script logic by traversing parsed representations.

### Programming Languages & Runtimes

- [Shell Script Runtimes](https://awesome-repositories.com/f/programming-languages-runtimes/shell-script-runtimes.md) — Executes shell commands and evaluates script logic within a custom programmable runtime environment.
- [Glob Expansion Control](https://awesome-repositories.com/f/programming-languages-runtimes/pattern-wildcards/glob-expansion-control.md) — Resolves dynamic string patterns and glob wildcards into literal values using shell-specific expansion rules.

### Software Engineering & Architecture

- [Abstract Syntax Tree Parsing](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-parsing.md) — Converts raw shell source code into structured abstract syntax trees for analysis and manipulation across dialects.
- [Dialect-Aware Parsers](https://awesome-repositories.com/f/software-engineering-architecture/integration-extensibility/extensibility/plugin-architectures/domain-specific/language-support-definitions/language-parsing-rules/dialect-aware-parsers.md) — Implements parsing logic that adapts to specific Bash and Zsh language specifications.
- [Syntax Validation Linters](https://awesome-repositories.com/f/software-engineering-architecture/syntax-tree-analysis/syntax-inspection/syntax-validation-linters.md) — Checks shell scripts for syntax errors and UTF-8 encoding issues before execution.

### Web Development

- [Shell Script Validators](https://awesome-repositories.com/f/web-development/frontend-development-tools/shell-script-validators.md) — Implements static parsing to detect syntax errors and verify UTF-8 encoding in shell scripts. ([source](https://github.com/mvdan/sh/blob/master/cmd/shfmt/shfmt.1.scd))
