piapia123
en

Shell Script Formatter

Format

Everything runs locally in your browser — nothing is uploaded

Input
Drop a file here to load its contents
Output

Tidy up a shell script that has lost its indentation: if / fi, for / done, while / do, case / esac, function bodies and subshells all line up by level, with case branch labels one level deeper and ;; returning to the branch level. The line this tool draws for itself is that it changes only the whitespace at the start of each line — not a single character inside a line. Shell is not a language you can reformat freely: everything between `<<EOF` and `EOF` is data, and one extra space changes it; continuations and newlines inside quotes depend on where they are. The cost is that it will not expand `if [ x ]; then echo ok; fi` into three lines — the benefit is that it will not break your script either.

Features

  • Structural indentation: if / for / while / case / function bodies / subshells
  • Case branches handled separately: labels one level deeper, ;; back to the branch level
  • Only leading whitespace changes — nothing inside a line
  • Heredoc bodies (<<EOF) are copied verbatim, since indenting them changes data
  • Multi-line strings are left alone, and quotes inside comments are not mistaken for string starts
  • Closing words followed by redirection (done < file) still line up
  • Indent width of 2 or 4, with optional trailing-whitespace trim and blank-line collapsing

How to use

  1. Paste the script
  2. The indentation is fixed as you type
  3. Adjust the width and the two whitespace options if needed
  4. Copy the result

FAQ

Why is there no "minify" option?
Because in shell it is a trap. Comments can sit inside a heredoc, where they are data and removing them changes the output; a script without a trailing newline collapses into an unintended single line; and the newlines around && and pipes are not free to move. Most scripts would survive, but the ones that do not fail silently and behave strangely at run time — so this tool does not do it.
Why leave heredocs untouched?
Because every line between `<<EOF` and `EOF` is data being written; the indentation there is part of the content. Adding indentation changes what the script outputs — if it is generating YAML or a snippet of code, wrong indentation breaks the whole file. The `<<-` form allows leading tabs, but only tabs, and that distinction is preserved too.
Does it change how the script behaves?
No. The tool rewrites only the leading whitespace of each line, after first identifying heredocs and multi-line strings and skipping them. Everything inside a line — extra spaces, special characters, comments — is left exactly as it was.
Is the script uploaded?
No. Formatting happens in the browser and the page sends no requests — deployment scripts often carry keys and internal addresses, and none of it leaves the machine.

Related tools