跳到正文
cccskills
免费在 GitHub 公开

bash-development

This skill should be used when the user asks to "write a bash script", "create a shell script", "implement bash function", "parse arguments in bash", "handle errors in bash", or mentions bash development, shell scripting, script templates, or modern bash patterns.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(9)

  • SKILL.md4.8 KB
  • references/bash_example_file.sh1.9 KB
  • references/bash_example_includes.bash872 B
  • references/bash-agent-notes.md4.3 KB
  • references/code-examples.md2.1 KB
  • references/pure-bash-bible-arrays.md4.2 KB
  • references/pure-bash-bible-files.md5.5 KB
  • references/pure-bash-bible-strings.md4.7 KB
  • references/pure-bash-bible-variables.md6.5 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Bash Development

Core patterns and best practices for Bash 5.1+ script development. Provides modern bash idioms, error handling, argument parsing, and pure-bash alternatives to external commands.

Script Foundation

Every script starts with the essential header:

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

set options explained:

  • -e - Exit immediately on command failure
  • -u - Treat unset variables as errors
  • -o pipefail - Pipeline fails if any command fails

Script Metadata Pattern

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

Error Handling

Implement trap-based error handling for robust scripts.

Code examples

Argument Parsing

Standard argument parsing template.

Code examples

Variable Best Practices

Always use curly braces and quote variables:

# Correct
"${variable}"
"${array[@]}"

# Incorrect
$variable
${array[*]}  # Use [@] for proper iteration

Use readonly for constants:

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

Note: Never use readonly in sourced scripts - it causes errors on re-sourcing.

String Operations (Pure Bash)

Prefer native bash parameter expansion over external tools:

# Trim whitespace
trimmed="${string#"${string%%[![:space:]]*}"}"
trimmed="${trimmed%"${trimmed##*[![:space:]]}"}"

# Lowercase/Uppercase (Bash 4+)
lower="${string,,}"
upper="${string^^}"

# Substring extraction
substring="${string:0:10}"      # First 10 chars
suffix="${string: -5}"          # Last 5 chars

# Replace patterns
replaced="${string//old/new}"   # Replace all
replaced="${string/old/new}"    # Replace first

# Strip prefix/suffix
no_prefix="${string#prefix}"    # Shortest match
no_prefix="${string##*/}"       # Longest match (basename)
no_suffix="${string%suffix}"    # Shortest match
no_suffix="${string%%/*}"       # Longest match

Array Operations

# Declaration
declare -a indexed_array=()
declare -A assoc_array=()

# Safe iteration with nullglob
shopt -s nullglob
for file in *.txt; do
    process "${file}"
done
shopt -u nullglob

# Array length
length="${#array[@]}"

# Append element
array+=("new_element")

# Iterate with index
for i in "${!array[@]}"; do
    printf '%d: %s\n' "${i}" "${array[i]}"
done

File Operations

# Read file to string
content="$(<"${file}")"

# Read file to array (Bash 4+)
mapfile -t lines < "${file}"

# Check file conditions
[[ -f "${file}" ]]    # Regular file exists
[[ -d "${dir}" ]]     # Directory exists
[[ -r "${file}" ]]    # Readable
[[ -w "${file}" ]]    # Writable
[[ -x "${file}" ]]    # Executable
[[ -s "${file}" ]]    # Non-empty

# Safe temp file creation
temp_file=$(mktemp)
trap 'rm -f "${temp_file}"' EXIT

Conditional Expressions

Use [[ ]] for conditionals (bash-specific, more powerful):

# String comparisons
[[ "${var}" == "value" ]]       # Equality
[[ "${var}" == pattern* ]]     # Glob matching
[[ "${var}" =~ ^regex$ ]]      # Regex matching

# Numeric comparisons
(( num > 10 ))                  # Arithmetic comparison
[[ "${num}" -gt 10 ]]          # Traditional syntax

# Compound conditions
[[ -f "${file}" && -r "${file}" ]]
[[ "${opt}" == "a" || "${opt}" == "b" ]]

Utility Functions

Code examples

Performance Guidelines

  • Use builtins over external commands when possible
  • Batch operations instead of loops for large datasets
  • Use printf over echo for portability and control
  • Avoid unnecessary subshells in tight loops
  • Use [[ ]] over [ ] for string comparisons

Additional Resources

Reference Files

For detailed patterns and examples:

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Add automated documentation updater to any Claude skill. Creates a Python sync script that downloads upstream docs, processes markdown for AI consumption, and maintains local cache with configurable refresh. Collects template variables, then delegates implementation through 5-phase workflow. Use when adding auto-updating reference documentation to plugins or skills.

中文简介正在准备中。当前显示原文说明。

Jamie-BitFlight/claude_skills672026年10月20日 更新

SAM-style feature initiation workflow — discovery through codebase analysis, architecture spec, task decomposition, validation, and context manifest. Use when a user asks to add a feature, plan a feature, or convert an idea into an executable SAM plan.

中文简介正在准备中。当前显示原文说明。

Jamie-BitFlight/claude_skills672026年10月20日 更新

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.

中文简介正在准备中。当前显示原文说明。

Jamie-BitFlight/claude_skills672026年10月20日 更新

Browser automation for AI agents using the agent-browser CLI and Playwright. Use when navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, logging into sites, or automating any browser task. Triggers on "open a website", "fill out a form", "click a button", "scrape data", "test this web app", "automate browser actions", or any programmatic web interaction request.

中文简介正在准备中。当前显示原文说明。

Jamie-BitFlight/claude_skills672026年10月20日 更新

Runs the description-drift experiment — spawns all Claude Code agents simultaneously to collect self-reported capabilities, then compares them against static frontmatter descriptions to reveal how reliable orchestrator routing based on descriptions actually is. Use when measuring description drift across the agent fleet, re-running the capability collection experiment, analyzing a specific agent's self-reported capabilities, or auditing whether frontmatter descriptions accurately reflect agent behavior.

中文简介正在准备中。当前显示原文说明。

Jamie-BitFlight/claude_skills672026年10月20日 更新

Create or adapt Claude Code agent definitions. Use when creating an agent, changing subagent configuration, selecting agent scope, or designing a specialized delegation role.

中文简介正在准备中。当前显示原文说明。

Jamie-BitFlight/claude_skills672026年10月20日 更新

查看 Jamie-BitFlight 的全部技能

报告此技能的问题