[GH-ISSUE #1060] [Bug] install.sh crashes on macOS (/bin/bash 3.2) with prefix_args[@]: unbound variable under set -u #388

Closed
opened 2026-10-15 18:24:35 +00:00 by bsakaguchi · 0 comments
Owner

Originally created by @ArianPashae on GitHub (Oct 8, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/1060

Summary

install.sh fails on macOS (Darwin) during actual installation (non---dry-run) because it expands an empty array "${prefix_args[@]}" under #!/bin/bash + set -euo pipefail.

Root Cause (install.sh:1-2, 88-95, 110)

  1. Line 1 pins the interpreter to #!/bin/bash. On macOS, /bin/bash is always Apple's system GNU Bash 3.2.57 (even when Homebrew Bash 5+ is installed under /opt/homebrew/bin/bash).
  2. Line 2 enables nounset (set -euo pipefail).
  3. Lines 88–95 initialize prefix_args=() as an empty array and only populate it on Linux:
    prefix_args=()
    if [[ "$platform" == "Linux" ]]; then
      prefix_args=(--prefix "$HOME/.local")
      install_bin="$HOME/.local/bin/rea"
    else
      npm_prefix="$(npm prefix --global)" || fail "the npm global prefix could not be read. Repair the npm configuration, then retry."
      install_bin="$npm_prefix/bin/rea"
    fi
    
  4. When --dry-run is used, the script exits early at line 106, so dry-run checks on macOS never reach line 110.
  5. On a real macOS install, execution reaches line 110:
    npm install --global "${prefix_args[@]}" "$PACKAGE@$version" || fail "..."
    
    In Bash < 4.4 (including macOS's Bash 3.2.57), expanding an empty array "${prefix_args[@]}" with set -u enabled triggers a fatal unbound variable error and immediately aborts the script before npm install is invoked:
    install.sh: line 110: prefix_args[@]: unbound variable
    

Reproduction

On any macOS system (or using Bash 3.2):

/bin/bash -c 'set -euo pipefail; prefix_args=(); echo "${prefix_args[@]}"'
# bash: prefix_args[@]: unbound variable

Proposed Fix

Use the standard Bash 3.2 nounset-safe array expansion idiom at install.sh:110:

npm install --global ${prefix_args[@]+"${prefix_args[@]}"} "$PACKAGE@$version" || fail "npm could not install REA. Check registry access and npm permissions, then retry."

I have submitted a focused PR with this fix.

Originally created by @ArianPashae on GitHub (Oct 8, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/1060 ### Summary `install.sh` fails on macOS (`Darwin`) during actual installation (non-`--dry-run`) because it expands an empty array `"${prefix_args[@]}"` under `#!/bin/bash` + `set -euo pipefail`. ### Root Cause (`install.sh:1-2, 88-95, 110`) 1. Line 1 pins the interpreter to `#!/bin/bash`. On macOS, `/bin/bash` is always Apple's system **GNU Bash 3.2.57** (even when Homebrew Bash 5+ is installed under `/opt/homebrew/bin/bash`). 2. Line 2 enables `nounset` (`set -euo pipefail`). 3. Lines 88–95 initialize `prefix_args=()` as an empty array and only populate it on Linux: ```bash prefix_args=() if [[ "$platform" == "Linux" ]]; then prefix_args=(--prefix "$HOME/.local") install_bin="$HOME/.local/bin/rea" else npm_prefix="$(npm prefix --global)" || fail "the npm global prefix could not be read. Repair the npm configuration, then retry." install_bin="$npm_prefix/bin/rea" fi ``` 4. When `--dry-run` is used, the script exits early at line 106, so dry-run checks on macOS never reach line 110. 5. On a real macOS install, execution reaches line 110: ```bash npm install --global "${prefix_args[@]}" "$PACKAGE@$version" || fail "..." ``` In **Bash < 4.4** (including macOS's Bash 3.2.57), expanding an empty array `"${prefix_args[@]}"` with `set -u` enabled triggers a fatal unbound variable error and immediately aborts the script before `npm install` is invoked: ```text install.sh: line 110: prefix_args[@]: unbound variable ``` ### Reproduction On any macOS system (or using Bash 3.2): ```bash /bin/bash -c 'set -euo pipefail; prefix_args=(); echo "${prefix_args[@]}"' # bash: prefix_args[@]: unbound variable ``` ### Proposed Fix Use the standard Bash 3.2 `nounset`-safe array expansion idiom at `install.sh:110`: ```bash npm install --global ${prefix_args[@]+"${prefix_args[@]}"} "$PACKAGE@$version" || fail "npm could not install REA. Check registry access and npm permissions, then retry." ``` I have submitted a focused PR with this fix.
bsakaguchi 2026-10-15 18:24:35 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#388
No description provided.