Bash and shell patterns for safety flags, quoting, traps, and ShellCheck. Load before any edit to a .sh, .bash, or .zsh file, shebang script, or Makefile recipe, however small, or for shell questions.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Bash Patterns?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ku5ic-bash-patterns)
---
name: bash-patterns
description: Bash and shell patterns for safety flags, quoting, traps, and ShellCheck. Load before any edit to a .sh, .bash, or .zsh file, shebang script, or Makefile recipe, however small, or for shell questions.
---
# Bash patterns
Default assumption: Bash 5.3 and ShellCheck 0.11, per the GNU Bash NEWS file and the ShellCheck changelog.
A row applies when the bash that runs the script is at least its version. Stock macOS `/bin/bash` is 3.2, so a 4.x or 5.x row fails under a `#!/bin/bash` script there; `#!/usr/bin/env bash` runs the first bash on PATH, on the user's machine the Homebrew 5.x build.
## Reference files
Loading this skill isn't enough. Before your next edit, read the file of every row that matches it. The rules live in those files, and this one only points at them.
| Before | Read |
| -------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| Writing bash, or upgrading bash or ShellCheck | [reference/upgrades.md](reference/upgrades.md) |
| Writing, changing, or reviewing bash code | [reference/anti-patterns.md](reference/anti-patterns.md) |
| Starting a script, or writing a function, trap, test, expansion, heredoc, or pipeline | [reference/practices.md](reference/practices.md) |
| Running or silencing ShellCheck, or formatting with shfmt | [reference/tooling.md](reference/tooling.md) |
| Typing a command at a zsh prompt, or moving a snippet tested in zsh into a bash script | [reference/quoting.md](reference/quoting.md) |