Skip to content

fix: run install.sh when piped via curl | bash (#36)#37

Merged
bigph00t merged 1 commit into
mainfrom
fix/install-sh-piped-bash-source
Jun 2, 2026
Merged

fix: run install.sh when piped via curl | bash (#36)#37
bigph00t merged 1 commit into
mainfrom
fix/install-sh-piped-bash-source

Conversation

@bigph00t

@bigph00t bigph00t commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #36. The documented install path curl -fsSL .../install.sh | bash failed with:

bash: line 203: BASH_SOURCE[0]: unbound variable

and installed nothing.

Root cause

The entrypoint guard referenced ${BASH_SOURCE[0]} directly while the script runs under set -euo pipefail. When piped, bash reads from stdin and the BASH_SOURCE array is empty, so ${BASH_SOURCE[0]} is an unbound-variable fatal error under set -u — aborting before install() runs.

Fix

-if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
+if [[ "${BASH_SOURCE[0]:-$0}" == "$0" ]]; then

Defaulting BASH_SOURCE[0] to $0 makes the guard correct in all three modes:

Mode BASH_SOURCE[0] $0 Result
piped (curl | bash) empty → defaults to $0 bash ✅ install runs
file (bash install.sh) install.sh install.sh ✅ install runs
sourced (tests) install.sh parent shell ✅ install skipped

⚠️ Note: the issue's suggested fix "${BASH_SOURCE[0]:-}" == "${0:-}" only silences the crash — when piped, $0 is "bash" while BASH_SOURCE[0] is empty, so the comparison is false and install still never runs (exit 0, nothing installed). Defaulting to $0 is required to actually run the installer.

Verification

  • bash -n install.sh — syntax OK
  • Piped (cat install.sh | bash) now enters install() and prints the banner (previously aborted at line 203)
  • scripts/test-installer-checksum.sh (which sources the script) still passes — install does not auto-run when sourced

The entrypoint guard referenced ${BASH_SOURCE[0]} directly while the
script runs under `set -euo pipefail`. When invoked as
`curl ... | bash`, bash reads from stdin and the BASH_SOURCE array is
empty, so `${BASH_SOURCE[0]}` aborts with "unbound variable" before
install() ever runs — the documented install path installed nothing.

Default BASH_SOURCE[0] to $0 so the guard is both safe under `set -u`
and still true when piped:

  - piped (curl|bash): BASH_SOURCE[0] empty -> defaults to $0 -> install runs
  - file (bash install.sh): BASH_SOURCE[0] == $0 -> install runs
  - sourced (tests): BASH_SOURCE[0] != $0 -> install skipped

Note: the simpler `${BASH_SOURCE[0]:-}` == `${0:-}` only silences the
crash; when piped $0 is "bash" so the comparison is false and install
still never runs. Defaulting to $0 is required to actually fix it.

Fixes #36

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@bigph00t bigph00t merged commit 35ec064 into main Jun 2, 2026
7 checks passed
@bigph00t bigph00t deleted the fix/install-sh-piped-bash-source branch June 2, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install.sh: "BASH_SOURCE[0]: unbound variable" when run via curl | bash

1 participant