一键导入
shell-workflow
Shell script workflow guidelines. Activate when working with shell scripts (.sh), bash scripts, or shell-specific tooling like shellcheck, shfmt.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Shell script workflow guidelines. Activate when working with shell scripts (.sh), bash scripts, or shell-specific tooling like shellcheck, shfmt.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Language-agnostic API design patterns covering REST and GraphQL, including resource naming, HTTP methods, status codes, versioning, pagination, filtering, authentication, error handling, and schema design. Activate when working with APIs, REST endpoints, GraphQL schemas, API documentation, OpenAPI/Swagger, JWT, OAuth2, endpoint design, API versioning, rate limiting, or GraphQL resolvers.
Git workflow and commit guidelines. Trigger keywords: git, commit, push, .git, version control. MUST be activated before ANY git commit, push, or version control operation. Includes security scanning for secrets (API keys, tokens, .env files), commit message formatting with HEREDOC, logical commit grouping (docs, test, feat, fix, refactor, chore, build, deps), push behavior rules, safety rules for hooks and force pushes, and CRITICAL safeguards for destructive operations (filter-branch, gc --prune, reset --hard). Activate when user requests committing changes, pushing code, creating commits, rewriting history, or performing any git operations including analyzing uncommitted changes.
Testing workflow patterns and quality standards. Activate when working with tests, test files, test directories, code quality tools, coverage reports, or testing tasks. Includes zero-warnings policy, targeted testing during development, mocking patterns, and best practices across languages.
Ansible automation workflow guidelines. Activate when working with Ansible playbooks, ansible-playbook, inventory files (.yml, .ini), or Ansible-specific patterns.
Claude Code AI-assisted development workflow. Activate when discussing Claude Code usage, AI-assisted coding, prompting strategies, or Claude Code-specific patterns.
Guidelines for containerized projects using Docker, Dockerfile, docker-compose, container, and containerization. Covers multi-stage builds, security, signal handling, entrypoint scripts, and deployment workflows.
| name | shell-workflow |
| description | Shell script workflow guidelines. Activate when working with shell scripts (.sh), bash scripts, or shell-specific tooling like shellcheck, shfmt. |
| location | user |
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
| Task | Tool | Command |
|---|---|---|
| Lint | shellcheck | shellcheck *.sh |
| Format | shfmt | shfmt -w *.sh |
| Coverage | bashcov | bashcov ./test.sh |
Scripts MUST use the portable shebang:
#!/usr/bin/env bash
POSIX-only scripts MAY use #!/bin/sh when bash features are not needed.
All bash scripts MUST enable strict mode at the top:
set -euo pipefail
| Flag | Meaning |
|---|---|
-e | Exit on error |
-u | Error on undefined variables |
-o pipefail | Fail on pipe errors |
For debugging, scripts MAY temporarily add set -x for trace output.
Scripts SHOULD NOT exceed 100 lines of code (excluding comments and blank lines).
When a script exceeds 100 lines:
Variables MUST be quoted to prevent word splitting and glob expansion:
# Correct
echo "$variable"
cp "$source" "$destination"
# Incorrect - MUST NOT use
echo $variable
cp $source $destination
Arrays MUST use proper expansion:
# Correct
"${array[@]}"
# For single string with spaces
"${array[*]}"
| Scope | Convention | Example |
|---|---|---|
| Environment/Global | UPPER_CASE | LOG_LEVEL, CONFIG_PATH |
| Local/Script | lower_case | file_count, temp_dir |
| Constants | UPPER_CASE | readonly MAX_RETRIES=3 |
Constants SHOULD be declared with readonly:
readonly CONFIG_FILE="/etc/app/config"
readonly -a VALID_OPTIONS=("start" "stop" "restart")
In bash scripts, [[ ]] MUST be used over [ ]:
# Correct - bash
if [[ -f "$file" ]]; then
echo "File exists"
fi
if [[ "$string" == "value" ]]; then
echo "Match"
fi
# Pattern matching (bash-only)
if [[ "$string" =~ ^[0-9]+$ ]]; then
echo "Numeric"
fi
POSIX scripts MUST use [ ] for compatibility.
Functions MUST use local for internal variables:
my_function() {
local input="$1"
local result=""
# Process input
result=$(process "$input")
echo "$result"
}
Function naming conventions:
process_file, validate_input_helper_functionTemporary files MUST be created with mktemp:
temp_file=$(mktemp)
temp_dir=$(mktemp -d)
Cleanup MUST be ensured with trap:
cleanup() {
rm -f "$temp_file"
rm -rf "$temp_dir"
}
trap cleanup EXIT
The EXIT trap ensures cleanup runs on normal exit, error, or interrupt.
Scripts MUST use standard exit codes:
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Misuse (invalid arguments, missing dependencies) |
Example usage:
main() {
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <argument>" >&2
exit 2
fi
if ! process_data "$1"; then
echo "Error: Processing failed" >&2
exit 1
fi
exit 0
}
Use || true when a command failure SHOULD NOT stop execution:
rm -f "$optional_file" || true
Use || exit 1 for critical operations:
cd "$required_dir" || exit 1
source "$config_file" || exit 1
command_that_might_fail || {
echo "Error: command failed" >&2
exit 1
}
| Feature | POSIX | Bash |
|---|---|---|
| Test syntax | [ ] | [[ ]] |
| Arrays | Not available | Supported |
local | Not standard | Supported |
source | Use . | Both work |
| Process substitution | Not available | <(cmd) |
When POSIX compatibility is REQUIRED:
# Instead of bash arrays, use positional parameters or newline-separated strings
files=$(find . -name "*.txt")
# Instead of [[ ]], use [ ]
if [ -f "$file" ]; then
echo "exists"
fi
# Instead of source, use .
. ./config.sh
User input MUST be validated:
validate_input() {
local input="$1"
if [[ -z "$input" ]]; then
echo "Error: Input cannot be empty" >&2
return 1
fi
if [[ ! "$input" =~ ^[a-zA-Z0-9_-]+$ ]]; then
echo "Error: Invalid characters in input" >&2
return 1
fi
return 0
}
Modern syntax MUST be used:
# Correct
result=$(command)
nested=$(echo $(inner_command))
# Incorrect - MUST NOT use backticks
result=`command`
Scripts SHOULD include consistent logging:
log_info() {
echo "[INFO] $*"
}
log_error() {
echo "[ERROR] $*" >&2
}
log_debug() {
[[ "${DEBUG:-0}" == "1" ]] && echo "[DEBUG] $*"
}
#!/usr/bin/env bash
set -euo pipefail
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly SCRIPT_NAME="$(basename "$0")"
usage() {
cat <<EOF
Usage: $SCRIPT_NAME [options] <argument>
Options:
-h, --help Show this help message
-v, --verbose Enable verbose output
EOF
}
main() {
local verbose=0
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-v|--verbose)
verbose=1
shift
;;
*)
break
;;
esac
done
if [[ $# -lt 1 ]]; then
usage >&2
exit 2
fi
# Script logic here
}
main "$@"