Skip to content

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

Backlog

Description

@ghchinoy

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

Activity

  1. added this to the v0.4.0 milestone on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions