Skip to content

fix(install): prevent unbound variable error on EXIT trap#25

Merged
JeelyWu merged 1 commit into
masterfrom
fix-install-script-unbound-variable
Jun 3, 2026
Merged

fix(install): prevent unbound variable error on EXIT trap#25
JeelyWu merged 1 commit into
masterfrom
fix-install-script-unbound-variable

Conversation

@JeelyWu
Copy link
Copy Markdown
Owner

@JeelyWu JeelyWu commented Jun 3, 2026

Bug Description

When the install script is piped to bash via curl -fsSL ... | bash, it reports a spurious error at the end:

bash: line 1: tmpdir: unbound variable
exit code: 1

The binary actually installs successfully to ~/.local/bin/tick, but the non-zero exit code is confusing and may break automation.

Root Cause

tmpdir was declared as a local variable inside main(). The EXIT trap references it, but after main() returns the local variable is destroyed. Under set -u this triggers an unbound variable error when the trap fires during script teardown.

Fix

Make tmpdir a global variable so the EXIT trap can safely reference it after main() returns.

Verification

  • Reproduced the bug with a minimal script: exit code 1 with unbound variable
  • After fix: clean exit with code 0

When install.sh is piped to bash (curl | bash), the EXIT trap
fires after main() returns. Since tmpdir was declared local,
it was destroyed when main() exited, causing 'tmpdir: unbound variable'
under set -u. The binary installed successfully, but the script
exited with code 1.

Fix by making tmpdir a global variable so the trap can reference
it after main() returns.
@JeelyWu JeelyWu merged commit f87b0bc into master Jun 3, 2026
1 check passed
@JeelyWu JeelyWu deleted the fix-install-script-unbound-variable branch June 4, 2026 15:39
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.

1 participant