fix(install): fail fast on Bash < 4.0 instead of crashing on mapfile - #25
Merged
Merged
Conversation
install.sh uses the `mapfile` builtin (5 call sites), which requires Bash
4.0+. The shebang is `#!/usr/bin/env bash` and stock macOS ships Bash
3.2.57 at /bin/bash, so a user on stock macOS hits a cryptic
"mapfile: command not found" partway through the run — after the script
has already done real filesystem work under `set -euo pipefail`.
Add an early version guard immediately after `set -euo pipefail`, before
any side effects. It checks ${BASH_VERSINFO[0]} (guarding against the
variable being unset), writes an actionable message to stderr naming the
macOS 3.2 default and the `brew install bash` remedy, and exits 1.
Also correct the "Requires:" header, which omitted the Bash 4.0
requirement entirely.
Verified: `/bin/bash ./install.sh --help` now prints the guard message
and exits 1; `/opt/homebrew/bin/bash ./install.sh --help` prints usage
and exits 0. shellcheck -S info reports only pre-existing SC2312 infos.
|
The change adds a Bash version guard that exits cleanly with an actionable error message when the script is run under Bash < 4.0 (e.g. macOS stock /bin/bash 3.2). The guard fires before any filesystem writes, so it prevents the previous failure mode of a mid-execution "mapfile: command not found" after changes have already started. Condition logic and placement are correct. VERDICT: PASS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
install.shcalls themapfilebuiltin at five sites (lines 251, 259, 502, 573, 585).mapfilewas introduced in Bash 4.0.The shebang is
#!/usr/bin/env bash, which resolves to whateverbashis first onPATH. Stock macOS ships Bash 3.2.57 at/bin/bash— Apple has never shipped Bash 4+ because of the GPLv3 license change. So on a machine without Homebrew bash (or with it absent from PATH), this script runs under 3.2.Reproduced on macOS:
Failure mode on stock macOS
Before this change there was no Bash version check anywhere in the script — no
BASH_VERSIONorBASH_VERSINFOreference at all. Combined withset -euo pipefail, that means:mapfileat line 251 and dies withmapfile: command not found.The header comment compounded it, listing
Requires: macOS, curl, python3and omitting the Bash 4 requirement entirely.The fix
An early fail-fast guard placed immediately after
set -euo pipefail, before any side effects:${BASH_VERSINFO[0]}, with:-so an unsetBASH_VERSINFOis caught rather than trippingset -u.mapfile, and gives the remedy (brew install bashplus the Apple-silicon and Intel invocation paths).The guard emits with plain
echo ... >&2rather than the script'serror()/fatal()helpers, because those are defined further down the file and the guard has to run first. A comment in the code says so.The
Requires:header now states the Bash 4.0+ requirement so the docs match reality.This is deliberately not a portability rewrite — the
mapfilecalls are untouched and no Bash 3.2 compatibility shim is added. The fix is a clear error plus honest documentation.Verification
Under stock Bash 3.2:
Under Homebrew Bash 5.3.15 — normal behavior, usage printed, exit 0:
shellcheck -S info install.shreports 8 SC2312 informational findings, all of which are pre-existing and unrelated to this change (verified by running shellcheck against the unmodified file — same 8). No new findings introduced, and no# shellcheck disabledirectives added.