Use when formatting shell scripts with shfmt. Covers consistent formatting patterns, shell dialect support, common issues, and editor integration.
View on GitHubTheBushidoCollective/han
jutsu-shfmt
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-shfmt/skills/shfmt-formatting/SKILL.md -a claude-code --skill shfmt-formattingInstallation paths:
.claude/skills/shfmt-formatting/# shfmt Formatting
Expert knowledge of shfmt's formatting capabilities, patterns, and integration with development workflows for consistent shell script formatting.
## Overview
shfmt formats shell scripts for readability and consistency. It parses scripts into an AST and prints them in a canonical format, eliminating style debates and ensuring uniformity across codebases.
## Supported Shell Dialects
shfmt supports multiple shell dialects with different syntax rules:
### POSIX Shell
Most portable, works with `/bin/sh` on any Unix system:
```bash
#!/bin/sh
# POSIX-compliant syntax only
# No arrays
# No [[ ]] tests
# No $() must work in all contexts
if [ "$var" = "value" ]; then
echo "match"
fi
```
### Bash
Most common for scripts, supports extended features:
```bash
#!/usr/bin/env bash
# Bash-specific features allowed
declare -a array=("one" "two" "three")
if [[ "$var" == "value" ]]; then
echo "match"
fi
result=$((1 + 2))
```
### mksh (MirBSD Korn Shell)
Korn shell variant with its own extensions:
```bash
#!/bin/mksh
# mksh-specific syntax
typeset -A assoc
assoc[key]=value
```
### Bats (Bash Automated Testing System)
For Bats test files:
```bash
#!/usr/bin/env bats
@test "example test" {
run my_command
[ "$status" -eq 0 ]
}
```
## Formatting Patterns
### Indentation
shfmt normalizes indentation throughout scripts:
**Before:**
```bash
if [ "$x" = "y" ]; then
echo "two spaces"
echo "four spaces"
echo "tab"
fi
```
**After (with `-i 2`):**
```bash
if [ "$x" = "y" ]; then
echo "two spaces"
echo "four spaces"
echo "tab"
fi
```
### Spacing
shfmt normalizes spacing around operators and keywords:
**Before:**
```bash
if[$x="y"];then
echo "no spaces"
fi
x=1;y=2;z=3
```
**After:**
```bash
if [ $x = "y" ]; then
echo "no spaces"
fi
x=1
y=2
z=3
```
### Semicolons and Newlines
Multiple statements are split to separate lines:
**Before:**
```bash
if [ "$x" ]; then echo "yes"; else echo "no"; fi
```
**After:**
`