Forrest logo
tool overview
On this page you find all important commands for the CLI tool shfmt. If the command you are looking for is missing please ask our AI.

shfmt

Shfmt is a command line tool designed to format shell scripts for better readability and maintainability. It can be used to automatically reformat shell scripts according to a consistent style guide.

Shfmt supports several shell languages including Bash, POSIX Shell, and Dash, making it versatile and applicable to a wide range of scripts. It parses the input script, indents it, and rewrites it using a specified style.

The tool provides various formatting options, such as indentation level, spaces around operators, line length limits, and more. These options can be customized to match the desired style guidelines.

Shfmt is compatible with most common shells and can be easily integrated into existing development workflows or build processes. It can be run from the command line or integrated into text editors such as Vim, Emacs, and Sublime Text.

The tool helps in ensuring consistent code formatting across a team or project, making it easier for developers to read, understand, and collaborate on shell scripts.

Shfmt can be used in CI/CD pipelines to enforce code formatting standards and prevent poorly formatted scripts from being merged into the codebase.

It supports recursive formatting, by applying formatting rules not just to single files, but also to entire directories or even large codebases.

The project is open source, licensed under the MIT License. Its source code is available on GitHub, providing transparency and allowing contributions from the community.

Shfmt has become popular among shell script developers, thanks to its simplicity, ease of use, and powerful formatting capabilities. It is actively maintained and frequently updated with new features and bug fixes.

List of commands for shfmt:

  • shfmt:tldr:3c95b shfmt: Write the result to the file instead of printing it to the terminal.
    $ shfmt --write ${filename}
    try on your machine
    explain this command
  • shfmt:tldr:b145f shfmt: Simplify the code, removing redundant pieces of syntax (i.e. removing "$" from vars in expressions).
    $ shfmt --simplify ${filename}
    try on your machine
    explain this command
  • shfmt:tldr:bf221 shfmt: Print a formatted version of a shell script.
    $ shfmt ${filename}
    try on your machine
    explain this command
  • shfmt:tldr:efb31 shfmt: List unformatted files.
    $ shfmt --list ${path-to-directory}
    try on your machine
    explain this command
tool overview