Communityコーディング&開発github.com

Jamie-BitFlight/bash-development

bashスクリプティング、シェルスクリプトの作成、bash関数の実装、引数解析、エラーハンドリング、近代的なbashパターンに関するユーザー要求に応答するスキルです。

bash-development とは?

このスキルは、Bash 5.1+ における最新のベストプラクティスとパターンを提供します。スクリプトの基礎(ヘッダー、`set -euo pipefail`)、トラップベースのエラーハンドリング、標準化された引数解析テンプレート、変数のベストプラクティス(readonly、引用符、中括弧)、純粋なbashによる文字列・配列・ファイル操作、高度な条件式(`[[ ]]`、`(( ))`)など、堅牢で保守性の高いシェルスクリプトを記述するための包括的なガイドです。AIエージェントや開発者は、このスキルを活用することで、外部コマンドへの依存を減らし、可搬性と性能に優れたbashコードを生成できます。Claude CodeやCursor、Codexなどのツールで動作し、参考ファイルとして完全なスクリプトテンプレートやユーティリティ関数、純粋bashの詳細リファレンスも提供しています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Jamie-BitFlight/claude_skills/tree/main/plugins/bash-development/skills/bash-development

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Bash 開発

Bash 5.1+ におけるスクリプト開発のための主要パターンとベストプラクティス。現代的な bash イディオム、エラーハンドリング、引数解析、外部コマンドに代わる純粋 bash による手法を提供します。

スクリプトの基礎

すべてのスクリプトは以下の必須ヘッダーから始めます:

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

set オプションの解説:

  • -e — コマンドが失敗したら即座に終了
  • -u — 未設定の変数をエラーとして扱う
  • -o pipefail — パイプライン内のいずれかのコマンドが失敗したらパイプ全体を失敗させる

スクリプトメタデータパターン

SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}")
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
readonly SCRIPT_VERSION="1.0.0"
readonly SCRIPT_NAME SCRIPT_DIR

エラーハンドリング

堅牢なスクリプトのためのトラップベースのエラーハンドリングを実装します。

コード例

引数解析

標準的な引数解析テンプレート。

コード例

変数のベストプラクティス

常に中括弧を使い、変数を引用符で囲みます:

# 正しい
"${variable}"
"${array[@]}"

# 誤り
$variable
${array[*]}  # 正しいイテレーションのためには [@] を使用

定数には readonly を使用:

readonly CONFIG_FILE="/etc/app/config"
readonly -a VALID_OPTIONS=("opt1" "opt2" "opt3")

注意: ソーススクリプト内では readonly を使用しないでください。再ソース時にエラーの原因となります。

文字列操作(純粋 Bash)

外部ツールよりもネイティブの bash パラメータ展開を推奨します:

# 空白のトリミング
trimmed="${string#"${string%%[![:space:]]*}"}"
trimmed="${trimmed%"${trimmed##*[![:space:]]}"}"

# 小文字 / 大文字 (Bash 4+)
lower="${string,,}"
upper="${string^^}"

# 部分文字列の抽出
substring="${string:0:10}"      # 最初の 10 文字
suffix="${string: -5}"          # 最後の 5 文字

# パターンの置換
replaced="${string//old/new}"   # すべて置換
replaced="${string/old/new}"    # 最初のみ置換

# プレフィックス / サフィックスの除去
no_prefix="${string#prefix}"    # 最短マッチ
no_prefix="${string##*/}"       # 最長マッチ (basename)
no_suffix="${string%suffix}"    # 最短マッチ
no_suffix="${string%%/*}"       # 最長マッチ

配列操作

# 宣言
declare -a indexed_array=()
declare -A assoc_array=()

# nullglob を使用した安全なイテレーション
shopt -s nullglob
for file in *.txt; do
    process "${file}"
done
shopt -u nullglob

# 配列の長さ
length="${#array[@]}"

# 要素の追加
array+=("new_element")

# インデックス付きイテレーション
for i in "${!array[@]}"; do
    printf '%d: %s\n' "${i}" "${array[i]}"
done

ファイル操作

# ファイルを文字列として読み込む
content="$(<"${file}")"

# ファイルを配列に読み込む (Bash 4+)
mapfile -t lines < "${file}"

# ファイルの状態を確認
[[ -f "${file}" ]]    # 通常ファイルが存在する
[[ -d "${dir}" ]]     # ディレクトリが存在する
[[ -r "${file}" ]]    # 読み取り可能
[[ -w "${file}" ]]    # 書き込み可能
[[ -x "${file}" ]]    # 実行可能
[[ -s "${file}" ]]    # 空でない

# 安全なテンポラリファイルの作成
temp_file=$(mktemp)
trap 'rm -f "${temp_file}"' EXIT

条件式

条件分岐には [[ ]] を使用します(bash 固有、より強力):

# 文字列比較
[[ "${var}" == "value" ]]       # 等価性
[[ "${var}" == pattern* ]]     # グロブマッチング
[[ "${var}" =~ ^regex$ ]]      # 正規表現マッチング

# 数値比較
(( num > 10 ))                  # 算術比較
[[ "${num}" -gt 10 ]]          # 従来の構文

# 複合条件
[[ -f "${file}" && -r "${file}" ]]
[[ "${opt}" == "a" || "${opt}" == "b" ]]

ユーティリティ関数

コード例

パフォーマンスガイドライン

  • 可能な場合は外部コマンドよりも組み込みコマンドを使用する
  • 大規模なデータセットではループではなくバッチ処理を行う
  • 移植性と制御のために echo ではなく printf を使用する
  • タイトループ内での不必要なサブシェルを避ける
  • 文字列比較には [ ] ではなく [[ ]] を使用する

追加リソース

参考ファイル

詳細なパターンと例については:

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

Jamie-BitFlight/agentskill-kaizen-meta-docs

Agentskill kaizen plugin documentation index. Load when needing to read about cross-platform notes, improvement plans, or DuckDB integration.

Jamie-BitFlight/bash-51-features

Bash 5.1 release features and improvements with practical examples. Use when working with Bash 5.1 features, epoch time variables, redirection enhancements, or when user asks about Bash 5.1 changes, new features, or version-specific capabilities.

Jamie-BitFlight/bash-52-features

Bash 5.2 release features and improvements with practical examples. Use when working with Bash 5.2 features, variable handling enhancements, readline improvements, or when user asks about Bash 5.2 changes, new features, or version-specific capabilities.

Jamie-BitFlight/bash-53-features

Bash 5.3 release features and improvements with practical examples. Use when working with Bash 5.3 features, new command substitution, GLOBSORT, loadable builtins, or when user asks about Bash 5.3 changes, new features, or version-specific capabilities.

Jamie-BitFlight/bash-lint

This skill should be used when the user asks to "lint bash script", "run shellcheck", "format shell script", "use shfmt", "fix shellcheck errors", or mentions shell script linting, formatting, code quality, or pre-commit hooks for bash.

Jamie-BitFlight/bash-logging

This skill should be used when the user asks to "add logging to bash script", "colorize output", "implement log levels", "CI/CD sections", "terminal colors in bash", or mentions logging functions, emoji output, collapsible CI sections, or shlocksmith.

Jamie-BitFlight/bash-portability

This skill should be used when the user asks about "POSIX compatibility", "portable shell scripts", "cross-shell compatibility", "bashisms", "shebang selection", or mentions writing scripts that work on different shells (bash, sh, dash, zsh) or different systems.

Jamie-BitFlight/bash-testing

This skill should be used when the user asks to "test bash script", "write shell tests", "use shunit2", "use shellspec", "create test suite for bash", or mentions unit testing, test frameworks, mocking, or test-driven development for shell scripts.

Jamie-BitFlight/brainstorming-skill

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or when users request help with ideation, marketing, and strategic planning. Explores user intent, requirements, and design before implementation using research-validated prompt patterns.

Jamie-BitFlight/clang-format

Configure clang-format code formatting. Use when: user mentions clang-format or .clang-format, analyzing code style/patterns, creating/modifying formatting config, troubleshooting formatting, brace styles/indentation/spacing/alignment/pointer alignment, or codifying conventions.

Jamie-BitFlight/commitlint

When setting up commit message validation for a project. When project has commitlint.config.js or .commitlintrc files. When configuring CI/CD to enforce commit format. When extracting commit rules for LLM prompt generation. When debugging commit message rejection errors.

Jamie-BitFlight/conventional-commits

When writing a git commit message. When task completes and changes need committing. When project uses semantic-release, commitizen, git-cliff. When choosing between feat/fix/chore/docs types. When indicating breaking changes. When generating changelogs from commit history.

Jamie-BitFlight/dasel-reference

Use when querying, modifying, or converting JSON, YAML, TOML, XML, CSV, HCL, or INI with dasel v3. Complete reference for selectors, functions, conditionals, variables, spread operator, type casting, and format-specific patterns.

Jamie-BitFlight/data-exploration

Use when exploring unknown structured data files with dasel v3 — discover schema, list keys, find nested values, sample arrays, identify data types across JSON, YAML, TOML, XML, CSV, HCL, INI formats

Jamie-BitFlight/data-transformation

Use when modifying, converting, or transforming structured data with dasel v3 — in-place mutations, format conversion, batch operations, array manipulation, object construction, and merge patterns across JSON, YAML, TOML, XML, CSV, HCL, INI

Jamie-BitFlight/delegate

Decompose substantive work into phases, dispatch each phase to a sub-agent, and adjudicate what comes back. Use whenever a request asks for implementation, investigation, a fix, a review, or any change to files — including small ones — and whenever you are about to read source or run a diagnostic yourself instead of handing it off. Also use when a report from a sub-agent needs judging, when a phase needs re-dispatching, or when a user names one instance of a pattern. Does not apply when your own prompt begins "Your ROLE_TYPE is sub-agent." — then follow references/sub-agent-contract.md instead.

Jamie-BitFlight/enterprise-hibernate-hbm

Dasel v3 query patterns for Hibernate .hbm.xml mapping files — entity-table binding, Java property-to-column extraction, one-to-many set/list/bag relationship tracing, many-to-one foreign key discovery, batch scanning across 60+ HBM files. Use when querying Hibernate ORM class mappings, extracting schema metadata from Java persistence layer, or auditing entity-column relationships in enterprise legacy codebases.

Jamie-BitFlight/enterprise-installanywhere

Dasel v3 query patterns for InstallAnywhere .iap_xml installer definitions — use when querying action sequences, discovering variables, resolving platform conditions, navigating panels, or comparing installer variants. Files are 2.5+ MB, 65,000+ lines — too large for context reads, requires structural dasel queries.

Jamie-BitFlight/enterprise-maven-pom

Dasel v3 selector patterns for Maven POM XML files — use when querying dependency versions, filtering by groupId or scope, extracting module hierarchy from parent POMs, or detecting version conflicts across enterprise multi-module Java projects. Load this skill when working with pom.xml files using dasel.

Jamie-BitFlight/enterprise-spring-xml

Dasel v3 selectors for Spring bean factory XML — use when querying any Spring ApplicationContext XML for bean discovery, dependency wiring, JMS destination mapping, property injection extraction, or cross-bean reference tracing. Load this skill before writing dasel selectors against Spring bean XML files (applicationContext.xml, *_beans.xml, spring-*.xml).

関連スキル