commands.sh

shfmt

all

Shell parser, formatter, and interpreter.

More info →

Options (5)

-l, --listboolean

List unformatted files

Example: shfmt {{[-l|--list]}} {{path/to/directory}}
-w, --writeboolean

Write the result to the file instead of printing it to the terminal

Example: shfmt {{[-w|--write]}} {{path/to/file}}
-s, --simplifyboolean

Simplify the code, removing redundant pieces of syntax (e.g. removing "$" from vars in expressions)

Example: shfmt {{[-s|--simplify]}} {{path/to/file}}
-i, --indentboolean

Specify the amount of spaces to use for indentation (0 for tabs, which is also the default)

Example: shfmt {{[-i|--indent]}} {{4}} {{path/to/file}}
--case-indentboolean

Format the code according to Google's style guide

Example: shfmt {{[-i|--indent]}} 2 {{[-ci|--case-indent]}} {{[-w|--write]}} {{path/to/file}}

Examples (6)

Print a formatted version of a shell script

shfmt path/to/file

List unformatted files

shfmt [-l|--list] path/to/directory

Write the result to the file instead of printing it to the terminal

shfmt [-w|--write] path/to/file

Simplify the code, removing redundant pieces of syntax (e.g. removing "$" from vars in expressions)

shfmt [-s|--simplify] path/to/file

Specify the amount of spaces to use for indentation (0 for tabs, which is also the default)

shfmt [-i|--indent] 4 path/to/file

Format the code according to Google's style guide

shfmt [-i|--indent] 2 [-ci|--case-indent] [-w|--write] path/to/file
made by @shridhargupta | data from tldr-pages