shfmt Shell script formatter
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
shfmt script.shshfmt -d .shfmt -l .shfmt -w script.sh
shfmt -l -w .shfmt -i 2 -cicat script.sh | shfmt
shfmt -f .Concepts
- Script *.sh or shebang
- Syntax tree dialect rules
- Formatted code flags / .editorconfig
- Result file, diff or list
Run
shfmt <file>
shfmt -w <file>
shfmt -d <path>
shfmt -l <path>
shfmt -l -w .shfmt -shfmt -l=0 <path>
shfmt --versionStyle (printer)
shfmt -i <n>
shfmt -cishfmt -bnshfmt -srshfmt -blshfmt -kpshfmt -mnshfmt -i 2 -ci -bn
Dialect and parsing
shfmt -ln <dialect>
shfmt -pshfmt -sshfmt --filename <name>
shfmt --detect <mode>
shfmt --apply-ignore
shfmt -f <path>
shfmt --to-jsonConfig (.editorconfig)
[*.sh]indent_style = spaceindent_size = 2case_indent = truebinary_next_line = truespace_redirects = truelanguage_dialect = bash
indent_style / indent_size
case_indent, binary_next_line
[[shell]] section header
ignore = trueRecipes
# fails the job when anything differsshfmt -d -i 2 -ci .
git ls-files -z '*.sh' | xargs -0 shfmt -w
shfmt -ln posix script.sh >/dev/null# prints line:col and error if invalid
# .pre-commit-config.yaml- repo: https://github.com/scop/pre-commit-shfmt rev: v3.14.1-1 hooks: - id: shfmt



