| name | me-shell-script |
| description | Use when writing or editing shell scripts (.sh files). Provides conventions for shebang, safety options, variable declarations, and Bash idioms used in this repository. |
| user-invocable | false |
Shell Script Guidelines
必須ヘッダー
すべての .sh ファイルに以下を先頭に記述する:
#!/usr/bin/env bash
set -euo pipefail
変数宣言
readonly REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
local -r name="value"
local name="value"
Bash イディオム
[[ -n "$var" ]] && echo "not empty"
[[ "$path" == *.sh ]] && shellcheck "$path"
result="$(command arg)"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
while IFS= read -r line; do
echo "$line"
done
関数
function my_function() {
local -r input="$1"
return 0
}
- 関数名はスネークケース
- 変数は必ずクォート:
"$var" (グロブ展開・単語分割を防ぐ)
エラー処理
if ! command -v jq >/dev/null 2>&1; then
echo "jq is required" >&2
exit 1
fi
[[ -f "$file" ]] || { echo "File not found: $file" >&2; exit 1; }
Lint
ファイル保存時に shellcheck が自動実行される(~/.claude/hooks/shellcheck-on-save.sh)。
手動実行: shellcheck <file>.sh