Skip to content
Back to skills

Bash Style

ASecurity

User-specific conventions for designing, writing, and reviewing Bash scripts and bats tests.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
ai-agentsgoshellbashtestingdocumentation

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add furedea/agent-config --skill bash-style --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Bash Style?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Bash Style
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/furedea-bash-style/badge)](https://www.skillsdirectory.com/skills/furedea-bash-style)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: bash-style
description: >
    User-specific conventions for designing, writing, and reviewing Bash scripts and bats tests.
---

# Shell Script Coding Style Guidelines

## Working Directory and Tracing

- Start every executable script with `#!/usr/bin/env bash`, followed by the strict-mode header:

```sh
#!/usr/bin/env bash
set -euo pipefail
```

    - `-e`: exit on error
    - `-u`: exit on undefined variable reference
    - `-o pipefail`: fail if any command in a pipe chain fails

  The static shebang rule checks only files that already have one, so a missing shebang is not reported. Enable all
  three options before the first command that does work; if a section must turn one off, turn it back on afterwards.
- Choose the working directory by responsibility. Hooks that operate on a project must use the
  target project's working directory. Resolve bundled resources relative to the script's location.
  Use `cd "$(dirname "$0")"` only when all relative operations should use that location.
- `set -x` prints expanded commands to stderr before execution. Keep tracing off by default, and never
  leave it on for scripts handling secrets or user input. Turn it on without editing the script: run
  `bash -x ./script.sh`.
- For a script that is debugged often, this opt-in line may follow the strict-mode header. It is optional, and no
  rule requires it:

```sh
if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi
```

If tracing was enabled, suppress it around noisy or sensitive sections. Restore it only
when subsequent commands are safe to trace:

```sh
set +x
# ... noisy or sensitive section ...
set -x
```

## usage Function

A script that takes arguments defines a `usage` function that prints its documentation with a heredoc inside its body:

```sh
function usage() {
  cat <<EOF
Description:
    Description of this script.

Usage:
    $0 [OPTIONS] <FILE>

Options:
    --version, -v: print "$(basename "$0")" version
    --help, -h: print this
EOF
}
```

For requested help (`--help`/`-h`), call `usage` and `exit 0`. For missing or invalid arguments,
call `usage >&2` and `exit 1`.

## Constants

Declare constants with `readonly`:

```sh
readonly INPUT_DIR="$SCRIPT_DIR/../data/input"
readonly MAX_RETRY=3
```

## Variables

- Use default values for variables that may be empty or undefined:
    ```sh
    readonly OUTPUT="${1:-output.txt}"   # default value
    readonly NAME="${NAME:?NAME is required}"  # error if unset/empty
    ```
- Define variables just before first use (minimize lifetime)

## Naming

Variables use `snake_case`, for example `input_file="..."`.

## Local Variables

Declare function-local variables with `local`:

```sh
function build_output() {
  local _src="$1"
  local _dst="$2"
  cp "$_src" "$_dst"
}
```

## Formatting

Indent with **2 spaces** (Google Shell Style Guide convention). Configure via `.editorconfig` at the project root; `shfmt` reads it automatically. Run `shfmt -d <file>` to check.

## Task-Specific References

- When creating a new script and a complete skeleton is useful, read
  [script_template.md](references/script_template.md).
- When designing, writing, or reviewing bats tests, read
  [bats_testing.md](references/bats_testing.md) for layout, fixtures, assertions, and test commands.
  Shell scripts use bats for tests; available tools are bats, shellcheck, and shfmt.

Read only the reference relevant to the task.

Files in this skill

  • SKILL.md3.3 KB
  • references/bats_testing.md6.5 KB
  • references/script_template.md689 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.