MAX_ATTEMPTS=5
RETRY_DELAY_SECONDS=2
retry_command() {
attempt=1
while [ "$attempt" -le "$MAX_ATTEMPTS" ]; do
if "$@"; then
return 0
fi
if [ "$attempt" -eq "$MAX_ATTEMPTS" ]; then
echo "command failed after $MAX_ATTEMPTS attempts" >&2
return 1
fi
sleep "$RETRY_DELAY_SECONDS"
attempt=$((attempt + 1))
done
}
Safe line reading
while IFS= read -r line; do
printf 'line=%s\n' "$line"
done < "$input_file"
Document manual verification for environment-dependent behavior.
Verify idempotency for repeatable automation scripts.
CI Required Quality Gates (check-only)
Run shellcheck -s sh.
Run shfmt -d -ln posix.
Run shell tests (shunit2/project equivalent).
Reject hidden failure paths and implicit behavior.
Optional Autofix Commands (local)
Run shfmt -w -ln posix.
Apply safe lint fixes, then rerun check-only commands.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: kentoshimizu-sw-agent-skills-sh-style-guide3description: SH Style Guide4---56# SH Style Guide78## Scope Boundaries9- Use this skill when the task matches the trigger condition described in `description`.10- Do not use this skill when the primary task falls outside this skill's domain.1112Use this skill to write and review POSIX `sh` scripts that run reliably across environments where Bash features are unavailable.1314## Trigger And Co-activation Reference1516- If available, use `references/trigger-matrix.md` for canonical co-activation rules.17- If available, resolve style-guide activation from changed files with `python3 scripts/resolve_style_guides.py <changed-path>...`.18- If available, validate trigger matrix consistency with `python3 scripts/validate_trigger_matrix_sync.py`.1920## Quality Gate Command Reference2122- If available, use `references/quality-gate-command-matrix.md` for CI check-only and local autofix mapping.2324## Quick Start Snippets2526### Portable script skeleton2728```sh29#!/bin/sh30set -eu3132SCRIPT_NAME=$(basename "$0")33TEMP_DIR=$(mktemp -d)3435cleanup() {36 rm -rf -- "$TEMP_DIR"37}3839on_error() {40 line_number="$1"41 echo "$SCRIPT_NAME: failed at line $line_number" >&242}4344trap cleanup EXIT HUP INT TERM45trap 'on_error "$LINENO"' ERR4647main() {48 echo "temp dir: $TEMP_DIR"49}5051main "$@"52```5354### Required environment variable check (no silent default)5556```sh57: "${API_TOKEN:?API_TOKEN is required}"58: "${API_BASE_URL:?API_BASE_URL is required}"59```6061### POSIX-safe argument handling (no arrays)6263```sh64run_curl() {65 url="$1"6667 curl --fail --silent --show-error \68 --header "Authorization: Bearer ${API_TOKEN}" \69 "$url"70}71```7273### Bounded retry loop7475```sh76MAX_ATTEMPTS=577RETRY_DELAY_SECONDS=27879retry_command() {80 attempt=181 while [ "$attempt" -le "$MAX_ATTEMPTS" ]; do82 if "$@"; then83 return 084 fi8586 if [ "$attempt" -eq "$MAX_ATTEMPTS" ]; then87 echo "command failed after $MAX_ATTEMPTS attempts" >&288 return 189 fi9091 sleep "$RETRY_DELAY_SECONDS"92 attempt=$((attempt + 1))93 done94}95```9697### Safe line reading9899```sh100while IFS= read -r line; do101 printf 'line=%s\n' "$line"102done < "$input_file"103```104105## Portability And Readability1061071. Target POSIX syntax only; avoid Bash/Zsh-specific features.1082. Use `set -eu` for executable scripts.1093. Prefer small functions and clear `main` orchestration.1104. Use uppercase constants and lowercase local variables.1115. Keep comments short and intent-focused.112113## Data Handling And Quoting1141151. Quote parameter expansion by default.1162. Avoid `eval` unless strictly required and heavily validated.1173. Replace magic numbers with named constants and explicit units.1184. Use `--` for destructive command path arguments.1195. Validate all external input before using it in commands.120121## Error Handling And Safety1221231. Return explicit non-zero status for expected failure modes.1242. Use `trap` for cleanup and signal handling.1253. Handle failures intentionally; do not mask with `|| true` unless justified.1264. Fail startup when required configuration is missing.1275. Let failures surface when root-cause fixing is required.128129## Testing And Verification1301311. Add shell tests (`shunit2` or project equivalent) for core paths.1322. Cover edge cases: empty input, whitespace paths, missing env vars, timeout/retry exhaustion.1333. Document manual verification for environment-dependent behavior.1344. Verify idempotency for repeatable automation scripts.135136## CI Required Quality Gates (check-only)1371381. Run `shellcheck -s sh`.1392. Run `shfmt -d -ln posix`.1403. Run shell tests (`shunit2`/project equivalent).1414. Reject hidden failure paths and implicit behavior.142143## Optional Autofix Commands (local)1441451. Run `shfmt -w -ln posix`.1462. Apply safe lint fixes, then rerun check-only commands.147148---149> Converted and distributed by [TomeVault](https://tomevault.io/claim/kentoshimizu) — claim your Tome and manage your conversions.150<!-- tomevault:4.0:skill_md:2026-04-15 -->
Run npx skillmds@latest add tomevault-io/kentoshimizu-sw-agent-skills-sh-style-guide in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
SH Style Guide It is listed under AI & ML on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.