hack/hero-demo/run.sh: fails on stock macOS /bin/bash 3.2 (requires Bash 4+ declare -A)

オープン 初心者向け
#784 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
80/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
bash
領域
cli

調査の方向性

hack/hero-demo/run.shから始め、特に102~103行目付近の連想配列の宣言と436行目付近のスコアボードのループを確認します。Bashのバージョン要件をhack/tour.shと比較します。macOS標準のBash 3.2で失敗を再現し、その後、スクリプトがエラーなくスコアボードを記録して表示することを確認します。完了条件は、各ステップの結果を保持したまま、デモがBash 3.2で実行できることです。

索引モデルが issue の本文から書いたものです。

説明

Summary

hack/hero-demo/run.sh uses Bash 4+ associative arrays (declare -A STATUS / declare -A NOTE on lines 102–103). On macOS without Homebrew Bash (5.3.x), its #!/usr/bin/env bash shebang invokes stock /bin/bash (3.2.57) even from the default zsh shell, failing immediately when recording and printing the scoreboard.

(For milestone v0.4.0.)

Reproduction

On a stock macOS machine (no Homebrew bash in PATH):

/bin/bash --version
# GNU bash, version 3.2.57(1)-release (arm64-apple-darwin25)

./hack/hero-demo/run.sh

Output:

./hack/hero-demo/run.sh: line 102: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
./hack/hero-demo/run.sh: line 103: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
...
./hack/hero-demo/run.sh: line 105: 2. Warm Workspace Snapshot: syntax error: invalid arithmetic operator (error token is ". Warm Workspace Snapshot")
...
./hack/hero-demo/run.sh: line 436: 2. Warm Workspace Snapshot: syntax error: invalid arithmetic operator (error token is ". Warm Workspace Snapshot")

Note: invoking zsh ./hack/hero-demo/run.sh directly also fails because line 37 relies on ${BASH_SOURCE[0]} and 0-indexed array indexing.

Suggested Fix

Keep the script Bash 3.2-compatible (matching hack/tour.sh, which avoids declare -A and runs cleanly on stock macOS /bin/bash 3.2.57).

Because STEPS is already a 5-element indexed array and every call site passes "${step}", replacing declare -A STATUS / declare -A NOTE with parallel indexed arrays and a small step_index lookup fixes lines 102–107 and 436 with zero changes to any of the mark_pass / mark_stub / mark_fail call sites:

STATUS=()
NOTE=()

step_index() {
  local i
  for i in "${!STEPS[@]}"; do
    if [[ "${STEPS[$i]}" == "$1" ]]; then
      printf '%s' "${i}"
      return 0
    fi
  done
  return 1
}

mark_result() {
  local idx
  idx="$(step_index "$1")" || return 1
  STATUS[$idx]="$2"
  NOTE[$idx]="$3"
}

mark_pass() { mark_result "$1" "🟢 PASS" "$2"; }
mark_stub() { mark_result "$1" "🟡 STUB" "$2"; }
mark_fail() { mark_result "$1" "🔴 FAIL" "$2"; }

And in the scoreboard loop (lines 431–437):

for i in "${!STEPS[@]}"; do
  if [[ -n "${ONLY_STEP}" && "${ONLY_STEP}" != "$((i + 1))" ]]; then
    continue
  fi
  printf "  %-34s | %-7s | %s\n" "${STEPS[$i]}" "${STATUS[$i]:-}" "${NOTE[$i]:-}"
done
主要言語
Go
スター
14.8k
フォーク
802
平均マージ
14時間 50分
マージ済み PR(30日)
133

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

google/ax のほかの issue

google/ax の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。