Skip to main content

Shell Script Formatter

Format and beautify Bash, sh, and Zsh shell scripts. Re-indent if/then/fi, for/while loops, case statements, and functions; choose 2/4 spaces or tabs, position binary operators, and space redirect operators.

Input

Output

Formatted Script
 
Was this helpful?

Guides

Paste a messy Bash, sh, or Zsh script and get back a clean, consistently indented version in one click. The Shell Script Formatter re-indents your code around the shell's block structure — if/then/fi, for/while/until/select loops, case/esac statements, and function definitions — so nesting is obvious at a glance and the whole script follows one style.

How to use it

  1. Paste your shell script into the input box (or click Try an example to load a deliberately messy sample).
  2. Adjust the options if you want a different result.
  3. The formatted script appears instantly on the right, ready to copy or download as script.sh.

Formatting runs entirely in your browser — nothing is uploaded to a server, which makes it safe for scripts that contain internal hostnames, paths, or other details you would rather not send anywhere.

Options

  • Indent Style — choose 2 spaces, 4 spaces, or tabs for each level of nesting.
  • Binary Operators — keep &&, ||, and | at the end of a line, or move them to the start of the next line (a common style for long, wrapped pipelines).
  • Indent case bodies in switch/case — when on, the commands under each case pattern get an extra level of indentation; when off, patterns and their bodies share a level.
  • Keep alignment padding — skip re-indentation entirely and only clean up trailing whitespace, blank lines, redirects, and operator positioning. Useful when you have hand-aligned columns you want to preserve.
  • Space after redirect operators — normalize >file to > file (and >>file to >> file), or remove that space. Redirects like >& are left untouched.

What it does

The formatter also trims trailing whitespace from every line, collapses runs of blank lines to at most two, and guarantees a single trailing newline. It is aware of shell syntax, so it does not rewrite the contents of single- or double-quoted strings, comments, $'...' ANSI-C strings, command substitutions, backticks, or heredoc bodies — those are passed through verbatim. Line continuations (a trailing \) are indented one extra level so wrapped commands stay readable.

Is this a full shell parser?

No — and it doesn't need to be. It's a fast, rule-based formatter that tracks indentation from shell keywords and brace/paren structure, the same heuristic approach editors use for on-the-fly re-indentation. It handles the vast majority of real-world scripts cleanly. For pathological one-liners with deeply interleaved constructs it favours doing something sensible over guaranteeing canonical output.

Does it change what my script does?

It only changes whitespace, indentation, and the position of line-continuation operators. The commands, arguments, quoting, and logic are left exactly as written, so a formatted script behaves the same as the original.

Which shells are supported?

Bash, POSIX sh, and Zsh share the block keywords and quoting rules this tool relies on, so scripts for any of them format correctly.

shellbashshzshbeautifyindentscript

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.