Skip to content

fix(hooks): replace BASH_SOURCE with POSIX-safe $0 for Linux compatibility#553

Closed
jd316 wants to merge 1 commit intoobra:mainfrom
jd316:fix/linux-bad-substitution-hooks
Closed

fix(hooks): replace BASH_SOURCE with POSIX-safe $0 for Linux compatibility#553
jd316 wants to merge 1 commit intoobra:mainfrom
jd316:fix/linux-bad-substitution-hooks

Conversation

@jd316
Copy link

@jd316 jd316 commented Feb 26, 2026

This PR completes the Linux/Ubuntu compatibility fix started in v4.3.1.

While the shell wrapper was updated, the internal session-start hook script still used the ${BASH_SOURCE[0]} syntax, which causes a 'Bad substitution' error on systems where /bin/sh is dash (like Ubuntu).

Changes:

  • Fixed hooks/session-start to use $0.
  • Updated docs/windows/polyglot-hooks.md to show the correct POSIX-safe pattern for future developers.

…ibility

This completes the fix started in v4.3.1 by addressing the same 'Bad substitution' issue in the session-start hook and documentation.
@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e4a2375 and a62f052.

📒 Files selected for processing (2)
  • docs/windows/polyglot-hooks.md
  • hooks/session-start

📝 Walkthrough

Walkthrough

Updated path-resolution logic in hook scripts from ${BASH_SOURCE[0]} to $0 across documentation and execution scripts, along with documentation formatting enhancements for Windows polyglot hooks configuration.

Changes

Cohort / File(s) Summary
Documentation
docs/windows/polyglot-hooks.md
Added Windows-specific bullet point, formatting polish, and updated path-detection logic example in run-hook.cmd wrapper from ${BASH_SOURCE[0]} to $0 for SCRIPT_DIR computation.
Hook Scripts
hooks/session-start
Changed SCRIPT_DIR resolution from ${BASH_SOURCE[0]:-$0} to $0.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Hops through scripts with glee,
$0 now resolves the way to be,
From BASH_SOURCE's nested dance,
To simpler paths—cross-platform's chance! 🎯

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main functional change: replacing BASH_SOURCE with POSIX-safe $0 for Linux compatibility, which matches the primary changes in hooks/session-start and the updated documentation.
Description check ✅ Passed The description is directly related to the changeset, explaining the rationale (Linux/Ubuntu compatibility fix), the specific problem ('Bad substitution' error with ${BASH_SOURCE[0]}), and listing the changes made (hooks/session-start and documentation updates).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jd316
Copy link
Author

jd316 commented Feb 26, 2026

@obra
Hey! Please review and merge this PR.

@obra obra added bug Something isn't working hooks Hook system (SessionStart, Stop, etc.) labels Mar 4, 2026
obra pushed a commit that referenced this pull request Mar 16, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@obra obra closed this in fd318b1 Mar 17, 2026
vladivis pushed a commit to vladivis/superpowers that referenced this pull request Mar 18, 2026
Replace ${BASH_SOURCE[0]:-$0} with $0 in hooks/session-start and the
polyglot-hooks docs example. BASH_SOURCE uses bash array syntax that
causes 'Bad substitution' on systems where /bin/sh is dash (Ubuntu).

Since session-start is always executed (never sourced), $0 and
BASH_SOURCE give the same result. Tested on Linux (bash + dash) and
Windows (Git Bash via CMD and direct).

Based on obra#553, closes obra#553.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
vladivis pushed a commit to vladivis/superpowers that referenced this pull request Mar 18, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hooks Hook system (SessionStart, Stop, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants