shfmt: Format shell programs

To update or switch versions, run webi shfmt@stable or webi shfmt@beta, etc.

Cheat Sheet

shfmt is a shell parser, formatter and interpretter that supports POSIX Shell, Bash and mksh.

Usage: shfmt <flags> <filepath>

Note: If given path is directory, all shell scripts in the directory will be used.


    Show version and exit.

    List files whose formatting differs from shfmt's.

    Write result to file instead of stdout.

    Error with a diff when the formatting differs.

    Simplify the code.

    Minify the code to reduce its size (implies -s).

-ln <str>
    Language variant to parse (bash/posix/mksh/bats, default "bash").

    Shorthand for -ln=posix.

-filename <str>
    Provide a name for the standard input file.

-i <uint>
    Indent: 0 for tabs (default), >0 for number of spaces.

    Binary ops like && and | may start a line.

    Switch cases will be indented.

    Redirect operators will be followed by a space.

    Keep column alignment paddings.

    Function opening braces are placed on a separate line.

    Recursively find all shell files and print the paths.

    Print syntax tree to stdout as a typed JSON.

See for more info.


Report an Issue Submit Installer