Shell Script Formatter (shfmt)

Paste a messy Bash or sh script and get it back with consistent indentation and spacing. The formatter is shfmt, running in your browser, so your script stays on your device.

Indent

Format uses shfmt, the standard shell script formatter. The options apply to Format.

Result

What a shell script formatter does

Shell scripts are often written quickly and then edited by many people, so indentation and spacing drift. A formatter reads the whole script and prints it back with one consistent layout: every if, for, while, case, and function body indented the same way, and even spacing around semicolons, pipes, and redirects. This tool uses shfmt, the standard formatter for Bash and sh, and changes only the layout, never what the script does.

Why use our shell script formatter

  • ·Free. No signup, no paywall, no limits.
  • ·Runs in your browser. shfmt runs locally as WebAssembly, so your script is never uploaded.
  • ·The real shfmt. The same formatter many teams run in their editors and CI.
  • ·Finds errors. Syntax errors are shown with their line and column.
  • ·Your house style. Choose tabs or spaces and how case branches, redirects, and pipes are laid out.

Shell formatter options

Format

Rewrites your script with consistent indentation and spacing using shfmt. Blocks like if, for, while, and functions are indented, and spacing around ; and | is made even.

Beforeif [ -f x ];then echo hi fiAfterif [ -f x ]; then echo hi fi

Indent

Choose tabs, 2 spaces, or 4 spaces for each level of nesting. shfmt uses tabs on its own, but 2 spaces is the most common choice for shell scripts, so it is the default here.

BeforeTabs, 2 spaces, or 4 spacesAfterYour choice per level

Indent case branches

Indents the branches of a case statement one level deeper than the case line. On by default.

Beforecase $1 in a) echo a ;; esacAftercase $1 in a) echo a ;; esac

Space after redirects

Puts a space between a redirect like > or >> and the file name.

Beforeecho hi >out.txtAfterecho hi > out.txt

Operators at line start

When a pipe or && command is split over several lines, moves the | or && to the start of the next line instead of the end of the current one.

Beforecat file | grep aAftercat file \ | grep a

When to format a Bash script

A formatter helps whenever a shell script is hard to read or needs to match a shared style. These are the cases that come up most:

  • ·Cleaning up pasted scripts. Fix the layout of a script from a forum post, a README, or an AI chat.
  • ·Deploy and CI scripts. Make build and deploy scripts readable before you commit them.
  • ·Finding a syntax error. Get the exact line of a missing fi, done, or closing quote.
  • ·Learning shell scripting. See how a well-structured Bash script is laid out.

Learn more about shell scripting

These references explain Bash and the formatter behind this tool:

Run shfmt and ShellCheck on your own scripts

This tool uses shfmt, the standard formatter for shell scripts. To format scripts on your own machine:

ToUse
Format a script in placeshfmt -w script.sh
Indent with 2 spaces instead of tabsshfmt -i 2 -w script.sh
Check without changing filesshfmt -d script.sh shows the changes as a diff
Find bugs, not just layoutshellcheck script.sh

shfmt only fixes layout. ShellCheck is a separate tool that warns about real bugs, like unquoted variables that break on spaces, so the two work well together. shfmt also reads indent settings from an .editorconfig file.

If you work across languages, these formatters run the same way, right in your browser:

Frequently asked questions

What is shfmt?
shfmt is the most widely used formatter for shell scripts. It parses a Bash, POSIX sh, or mksh script and prints it back with consistent indentation and spacing. This tool runs the real shfmt, compiled to WebAssembly, in your browser.
How do I format a Bash script online?
Paste your script into the input box, pick your indentation and layout options, then click Format. The clean version appears below. Click the copy button to copy it, or download it as a .sh file.
Does formatting change how my script runs?
No. shfmt only changes indentation, spaces, and line layout. Commands, arguments, quotes, and here-documents stay the same, so the script behaves exactly as before.
Why does the formatter show an error?
shfmt has to parse the whole script before it can format it. If a keyword is missing (for example an if without fi) or a quote is not closed, it stops and shows the line and column of the problem so you can fix it.
Does it work with zsh or fish scripts?
It works with Bash, POSIX sh, and mksh. Most zsh scripts that stick to Bash-style syntax format fine, but zsh-only features and fish scripts are not supported.
Is my script kept private?
Yes. shfmt runs entirely in your browser as WebAssembly. Your script is never uploaded to a server or saved anywhere, so it is safe to paste scripts that contain internal paths or hostnames. Once the page has loaded you can even use it offline.