Loading...
Loading...
Style, review, and refactoring standards for Bash shell scripting. Trigger when `.sh` files, files with `#!/usr/bin/env bash` or `#!/bin/bash`, or CI workflow blocks with `shell: bash` are created, modified, or reviewed and Bash-specific quality controls (quoting safety, error handling, portability, readability) must be enforced. Do not use for generic POSIX `sh`, PowerShell, or language-specific application style rules. In multi-language pull requests, run together with other applicable `*-style-guide` skills.
npx skill4agent add kentoshimizu/sw-agent-skills bash-style-guidedescriptionreferences/trigger-matrix.mdpython3 scripts/resolve_style_guides.py <changed-path>...python3 scripts/validate_trigger_matrix_sync.pyreferences/quality-gate-command-matrix.md#!/usr/bin/env bash
set -euo pipefail
readonly SCRIPT_NAME="$(basename "$0")"
readonly TEMP_DIR="$(mktemp -d)"
cleanup() {
rm -rf -- "${TEMP_DIR}"
}
on_error() {
local line="$1"
local exit_code="$2"
echo "${SCRIPT_NAME}: failed at line ${line} (exit=${exit_code})" >&2
}
trap cleanup EXIT
trap 'on_error "$LINENO" "$?"' ERR
main() {
echo "working dir: ${TEMP_DIR}"
}
main "$@": "${API_TOKEN:?API_TOKEN is required}"
: "${API_BASE_URL:?API_BASE_URL is required}"run_curl() {
local url="$1"
local -a args=(
--fail
--silent
--show-error
--header "Authorization: Bearer ${API_TOKEN}"
"${url}"
)
curl "${args[@]}"
}readonly MAX_ATTEMPTS=5
readonly RETRY_DELAY_SECONDS=2
retry_command() {
local attempt=1
while (( attempt <= MAX_ATTEMPTS )); do
if "$@"; then
return 0
fi
if (( attempt == MAX_ATTEMPTS )); then
echo "command failed after ${MAX_ATTEMPTS} attempts" >&2
return 1
fi
sleep "${RETRY_DELAY_SECONDS}"
((attempt++))
done
}while IFS= read -r line; do
printf 'line=%s\n' "${line}"
done < "${input_file}"#!/usr/bin/env bashset -euo pipefailmainMAX_RETRIESretry_countlocal"${var}""${array[@]}"TIMEOUT_SECONDSevaltrapif ! cmd; then ... fi|| true--rm -- "$target"mktempsudobatsbats#!/usr/bin/env bats
@test "fails when required env var is missing" {
run ./script.sh
[ "$status" -ne 0 ]
[[ "$output" == *"API_TOKEN is required"* ]]
}shellcheckshfmt -dbats test/shfmt -wshellcheck