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 the untidy script into the left editor, or open a .sh, .bash, .zsh or .txt file with Upload.
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
Does it matter whether my script is sh or 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?
Yes. Re-indenting the script is done by JavaScript running in this tab. Deploy scripts with hostnames, paths or tokens in them are never sent to a server, so they stay private.