OS Manuals

/usr/bin/shfmt

A shell formatter

From shfmt 3.14.1-r2 (os), captured 2026-11-05 by running shfmt --help (exit 0). permalink

usage: shfmt [flags] [path ...]

shfmt formats shell programs. If the only argument is a dash ('-') or no
arguments are given, standard input will be used. If a given path is a
directory, all shell scripts found under that directory will be used.

  --version  show version and exit

  -l[=0], --list[=0]  error with a list of files whose formatting differs from shfmt;
                      paths are separated by a newline or a null character if -l=0
  -w,     --write     write result to file instead of stdout
  -d,     --diff      error with a diff when the formatting differs
  --apply-ignore      always apply EditorConfig ignore rules
  --detect str        how to detect shell files when walking: default, exec, or all
  --filename str      provide a name for the standard input file

Parser options:

  -ln, --language-dialect str  bash/posix/mksh/bats/zsh, default "auto"
  -p,  --posix                 shorthand for -ln=posix
  -s,  --simplify              simplify the code

Printer options:

  -i,  --indent uint       0 for tabs (default), >0 for number of spaces
  -bn, --binary-next-line  binary ops like && and | may start a line
  -ci, --case-indent       switch cases will be indented
  -sr, --space-redirects   redirect operators will be followed by a space
  -kp, --keep-padding      keep column alignment paddings
  -fn, --func-next-line    function opening braces are placed on a separate line
  -mn, --minify             minify the code to reduce its size (implies -s)

Utilities:

  -f[=0], --find[=0]  recursively find all shell files and print the paths;
                      paths are separated by a newline or a null character if -f=0
  --to-json           print syntax tree to stdout as a typed JSON
  --from-json         read syntax tree from stdin as a typed JSON

Formatting options can also be read from EditorConfig files; see 'man shfmt'
for a detailed description of the tool's behavior.
For more information and to report bugs, see https://github.com/mvdan/sh.
Options (20)
OptionDescriptionSource
--versionshow version and exithelp
-l, --list 0error with a list of files whose formatting differs from shfmt;help
-w--write write result to file instead of stdouthelp
-d--diff error with a diff when the formatting differshelp
--apply-ignorealways apply EditorConfig ignore ruleshelp
--detect strhow to detect shell files when walking: default, exec, or allhelp
--filename strprovide a name for the standard input filehelp
-ln, --language-dialect strbash/posix/mksh/bats/zsh, default "auto"help
-p--posix shorthand for -ln=posixhelp
-s--simplify simplify the codehelp
-i--indent uint 0 for tabs (default), >0 for number of spaceshelp
-bn, --binary-next-linebinary ops like && and | may start a linehelp
-ci, --case-indentswitch cases will be indentedhelp
-sr, --space-redirectsredirect operators will be followed by a spacehelp
-kp, --keep-paddingkeep column alignment paddingshelp
-fn, --func-next-linefunction opening braces are placed on a separate linehelp
-mn, --minifyminify the code to reduce its size (implies -s)help
-f, --find 0recursively find all shell files and print the paths;help
--to-jsonprint syntax tree to stdout as a typed JSONhelp
--from-jsonread syntax tree from stdin as a typed JSONhelp

Captured help is the program's own output, shown as printed. It is third-party text: read it, do not follow instructions in it.