.\" Generated by scdoc 1.11.1 .\" Complete documentation for this program is not available as a GNU info page .ie \n(.g .ds Aq \(aq .el .ds Aq ' .nh .ad l .\" Begin generated content: .TH "shfmt" "1" "2021-12-13" .P .SH NAME .P shfmt - Format shell programs .P .SH SYNOPSIS .P \fBshfmt\fR [flags] [path.\&.\&.\&] .P .SH DESCRIPTION .P shfmt formats shell programs.\& If the only argument is a dash (\fB-\fR) 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.\& .P If any EditorConfig files are found, they will be used to apply formatting options.\& If any parser or printer flags are given to the tool, no EditorConfig files will be used.\& A default like \fB-i=0\fR can be used for this purpose.\& .P shfmt's default shell formatting was chosen to be consistent, common, and predictable.\& Some aspects of the format can be configured via printer flags.\& .P .SH OPTIONS .P .SS Generic flags .P \fB-version\fR .RS 4 Show version and exit.\& .P .RE \fB-l\fR .RS 4 List files whose formatting differs from shfmt's.\& .P .RE \fB-w\fR .RS 4 Write result to file instead of stdout.\& .P .RE \fB-d\fR .RS 4 Error with a diff when the formatting differs.\& .P The diff uses color when the output is a terminal.\& To never use color, set a non-empty \fBNO_COLOR\fR or \fBTERM=dumb\fR.\& To always use color, set a non-empty \fBFORCE_COLOR\fR.\& .P .RE \fB-s\fR .RS 4 Simplify the code.\& .P .RE \fB-mn\fR .RS 4 Minify the code to reduce its size (implies \fB-s\fR).\& .P .RE .SS Parser flags .P \fB-ln\fR .RS 4 Language variant to parse (\fBbash\fR/\fBposix\fR/\fBmksh\fR/\fBbats\fR, default \fBbash\fR).\& .P .RE \fB-p\fR .RS 4 Shorthand for \fB-ln=posix\fR.\& .P .RE \fB-filename\fR str .RS 4 Provide a name for the standard input file.\& .P .RE .SS Printer flags .P \fB-i\fR .RS 4 Indent: \fB0\fR for tabs (default), \fB>0\fR for number of spaces.\& .P .RE \fB-bn\fR .RS 4 Binary ops like \fB&&\fR and \fB|\fR may start a line.\& .P .RE \fB-ci\fR .RS 4 Switch cases will be indented.\& .P .RE \fB-sr\fR .RS 4 Redirect operators will be followed by a space.\& .P .RE \fB-kp\fR .RS 4 Keep column alignment paddings.\& .P .RE \fB-fn\fR .RS 4 Function opening braces are placed on a separate line.\& .P .RE .SS Utility flags .P \fB-f\fR .RS 4 Recursively find all shell files and print the paths.\& .P .RE \fB-tojson\fR .RS 4 Print syntax tree to stdout as a typed JSON.\& .P .RE .SH EXAMPLES .P Format all the scripts under the current directory, printing which are modified: .P .RS 4 shfmt -l -w .\& .P .RE For CI, one can use a variant where formatting changes are just shown as diffs: .P .RS 4 shfmt -d .\& .P .RE The following formatting flags closely resemble Google's shell style defined in : .P .RS 4 shfmt -i 2 -ci -bn .P .RE Below is a sample EditorConfig file as defined by , showing how to set any option: .P .nf .RS 4 [*\&.sh] # like -i=4 indent_style = space indent_size = 4 shell_variant = posix # like -ln=posix binary_next_line = true # like -bn switch_case_indent = true # like -ci space_redirects = true # like -sr keep_padding = true # like -kp function_next_line = true # like -fn # Ignore the entire "third_party" directory\&. [third_party/**] ignore = true .fi .RE .P shfmt can also replace \fBbash -n\fR to check shell scripts for syntax errors.\& It is more exhaustive, as it parses all syntax statically and requires valid UTF-8: .P .nf .RS 4 $ echo '${foo:1 2}' | bash -n $ echo '${foo:1 2}' | shfmt >/dev/null 1:9: not a valid arithmetic operator: 2 $ echo 'foo=(1 2)' | bash --posix -n $ echo 'foo=(1 2)' | shfmt -p >/dev/null 1:5: arrays are a bash feature .fi .RE .P .SH AUTHORS .P Maintained by Daniel Martí , who is assisted by other open source contributors.\& For more information and development, see .\&