Bash Formatter
Format and beautify Bash/Shell scripts online. Fix indentation and normalize shell script syntax.
Input
Output
What is Bash?
Bash (Bourne Again Shell) is the default command-line shell on most Linux distributions and macOS. Shell scripts are widely used for automation, deployment pipelines, and system administration tasks.
The Bash Formatter normalizes indentation (2 spaces per level), handles if/then/fi, for/do/done, while/do/done, and function blocks, and preserves comments. For deeper validation, check out ShellCheck.
How to Use
Paste your shell script
Paste raw or messy Bash/shell script into the left editor, or click Upload to load a file.
Instant formatting
The formatter automatically normalizes indentation with 2 spaces per level for if/fi, do/done, and function blocks.
Copy or download
Use the Copy button to copy the result, or Download to save it as a .sh file.
Formatting Example
Example: Format a backup script
Unformatted input:
#!/bin/bash
if [ ! -d "/backup" ]; then
mkdir /backup
fi
for f in *.log; do
cp "$f" "/backup/$f.$(date +%Y%m%d)"
doneFormatted output:
#!/bin/bash
if [ ! -d "/backup" ]; then
mkdir /backup
fi
for f in *.log; do
cp "$f" "/backup/$f.$(date +%Y%m%d)"
doneFrequently Asked Questions
What is the difference between sh and bash?
sh is the POSIX shell standard. Bash is a superset of sh with additional features. This formatter handles both sh and bash syntax.
Should I use tabs or spaces in shell scripts?
Both are valid, but 2 or 4 spaces are common conventions. The Google Shell Style Guide recommends 2 spaces. This formatter uses 2 spaces.
Can I format zsh scripts?
Yes. zsh shares most syntax with bash, so the formatter handles zsh scripts well.
Is my code safe when I use this tool?
Absolutely. All formatting runs entirely in your browser using JavaScript. Your shell script is never sent to any server, so your code stays completely private.