.\" Generated by scdoc 1.11.2 .\" 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" "2023-07-24" .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, \fB--list\fR .RS 4 List files whose formatting differs from shfmt'\&s.\& .P .RE \fB-w\fR, \fB--write\fR .RS 4 Write result to file instead of stdout.\& .P .RE \fB-d\fR, \fB--diff\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, \fB--simplify\fR .RS 4 Simplify the code.\& .P .RE \fB-mn\fR, \fB--minify\fR .RS 4 Minify the code to reduce its size (implies \fB-s\fR).\& .P .RE .SS Parser flags .P \fB-ln\fR, \fB--language-dialect\fR .RS 4 Language dialect (\fBbash\fR/\fBposix\fR/\fBmksh\fR/\fBbats\fR, default \fBauto\fR).\& .P When set to \fBauto\fR, the language is detected from the input filename, as long as it has a shell extension like \fBfoo.\&mksh\fR.\& Otherwise, if the input begins with a shell shebang like \fB#!\&/bin/sh\fR, that'\&s used instead.\& If neither come up with a result, \fBbash\fR is used as a fallback.\& .P The filename extension \fB.\&sh\fR is a special case: it implies \fBposix\fR, but may be overriden by a valid shell shebang.\& .P .RE \fB-p\fR, \fB--posix\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, \fB--indent\fR .RS 4 Indent: \fB0\fR for tabs (default), \fB>0\fR for number of spaces.\& .P .RE \fB-bn\fR, \fB--binary-next-line\fR .RS 4 Binary ops like \fB&&\fR and \fB|\fR may start a line.\& .P .RE \fB-ci\fR, \fB--case-indent\fR .RS 4 Switch cases will be indented.\& .P .RE \fB-sr\fR, \fB--space-redirects\fR .RS 4 Redirect operators will be followed by a space.\& .P .RE \fB-kp\fR, \fB--keep-padding\fR .RS 4 Keep column alignment paddings.\& .P .RE \fB-fn\fR, \fB--func-next-line\fR .RS 4 Function opening braces are placed on a separate line.\& .P .RE .SS Utility flags .P \fB-f\fR, \fB--find\fR .RS 4 Recursively find all shell files and print the paths.\& .P .RE \fB--to-json\fR .RS 4 Print syntax tree to stdout as a typed JSON.\& .P .RE \fB--from-json\fR .RS 4 Read syntax tree from stdin 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 # --language-variant binary_next_line = true switch_case_indent = true # --case-indent space_redirects = true keep_padding = true function_next_line = true # --func-next-line # 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 .\&