Files
openclaw/scripts/docs-spellcheck.sh
Vitalii fef57f99ba fix(scripts): docs-spellcheck.sh fails on bash 3.2 with set -u
scripts/docs-spellcheck.sh uses set -u and constructs args=( ... "${write_flag[@]}" ), where write_flag may be an empty array. On bash 3.2 (still the default /bin/bash on macOS), referencing an empty array under set -u raises an unbound variable error. Newer bash (>= 4.4) handles this expression correctly, which is why the script ships green on Linux CI runners.

Switch to the bash 3.2-safe parameter expansion ${write_flag[@]+"${write_flag[@]}"}: it expands to nothing when the array is empty and to the array contents otherwise, preserving --write behavior unchanged.

Also fixes overrideable -> overridable in docs/reference/test.md, which the now-running spellcheck surfaces.

Repro:
  bash scripts/docs-spellcheck.sh                # was: write_flag[@]: unbound variable, exit 1
  bash scripts/docs-spellcheck.sh                # now: codespell runs to completion
2026-05-25 20:56:52 +01:00

45 lines
904 B
Bash

#!/usr/bin/env bash
set -euo pipefail
mode="${1:-}"
write_flag=()
if [[ "$mode" == "--write" ]]; then
write_flag=(-w)
fi
args=(
README.md
docs
--skip=*.png,*.jpg,*.jpeg,*.gif,*.svg
-D
-
-D
scripts/codespell-dictionary.txt
-I
scripts/codespell-ignore.txt
${write_flag[@]+"${write_flag[@]}"}
)
if command -v codespell >/dev/null 2>&1; then
codespell "${args[@]}"
exit 0
fi
if command -v python3 >/dev/null 2>&1; then
python3 -m pip install --user --disable-pip-version-check --break-system-packages codespell >/dev/null 2>&1 || \
python3 -m pip install --user --disable-pip-version-check codespell >/dev/null 2>&1
user_bin="$(python3 - <<'PY'
import site
print(f"{site.USER_BASE}/bin")
PY
)"
if [[ -x "${user_bin}/codespell" ]]; then
"${user_bin}/codespell" "${args[@]}"
exit 0
fi
fi
echo "codespell unavailable: install codespell or python3" >&2
exit 1