Shell Script Formatter: Re-indent if, for, while and case Blocks
Fixes indentation of Bash and POSIX shell scripts and keeps heredocs and multi-line strings intact.
Use the tool
Why this tool exists
Shell scripts get edited in many hands and lose their layout. The tool follows if, then, else, fi, for, while, do, done, case, esac and brace blocks, indents case bodies one level, adds a level for lines continued with a backslash, and leaves heredoc bodies and multi-line quotes alone.
It is not shfmt, because no WASM or third-party code is allowed here, and shfmt was not available to compare. As a check, 398 real system scripts were re-indented: all still parsed with bash -n and only whitespace changed.
How to use it
- Paste the script.
- Pick tabs or spaces.
- Read the result.
- Run shellcheck for real problems.
Frequently asked questions
Does it fix quoting or other errors?
No. Only indentation and blank lines.
Which case layout is used?
Patterns at the level of case and bodies one level deeper, as shfmt does by default.
What about complicated parentheses?
Subshell and multi-line command substitutions are not tracked and may keep their old indent.
Is my input sent anywhere?
No. Everything runs in your browser and nothing is uploaded.