Repository navigation
Give a script found through PATH its path as $0 - #32
Merged
Merged
Conversation
When a shell script was found by a PATH search, gash set $0 to the bare name as typed (`probe`), so `dirname "$0"` was `.`. bash, dash and zsh execve() the path they found, which becomes $0. The npm/pnpm/yarn shims in node_modules/.bin locate their package with `dirname "$0"`, so with gash as npm's script-shell they resolved targets from the current directory instead (pnpm i failing with "Cannot find module"). A PATH hit now records the PATH entry joined with the name of the file found (`./node_modules/.bin/probe`, or the absolute entry as given), and that becomes $0 and BASH_SOURCE for scripts run in-process and the script argument when a separate gash is started. Names typed with a slash and `bash script.sh` are unchanged. Hits in relative PATH entries are no longer hashed, since they depend on the current directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
When gash ran a shell script it found by searching PATH,
$0was the bare name as typed (probe), sodirname "$0"came out as.. bash, dash and zsh set$0to the path they found, because they execve() that path.Every npm/pnpm/yarn POSIX shim in
node_modules/.binfinds its package withdirname "$0". With gash as npm'sscript-shell, those shims resolved their target from the current directory. For example,pnpm ifailed withCannot find module '...\packages\@reflect\machine-cache\bin\reuse-build.cjs'.Fix
find_in_pathfinds a file, it now records the PATH entry joined with the name of the file found (Resolved::found_as). Examples:./node_modules/.bin/probe,node_modules/.bin/probe,/abs/dir/probe, or./probefor an empty entry. Under PATHEXT lookup it is the file actually found.$0andBASH_SOURCE. When gash starts a separate shell for a script, it passes that path as the script argument.$0exactly as typed.bash script.shis unchanged.The output matches Git Bash for relative, absolute, trailing-slash and empty PATH entries, a
PATH=... cmdprefix, pipelines, background jobs, andGASH_NO_INPROC=1.Tests
tests/scripts/075_path_lookup_dollar0.sh. It covers relative and absolute PATH entries, an npm-style shim run from another directory, and the cases that must not change. The expected output was generated from Git Bash. The test fails onmain(0=probe,dirname=.).cargo test --releasepasses, including all 75 compat scripts.pnpm inow runs theelectron-webauthnandpasskeyinstall scripts (reuse-build ...) with gash asscript-shell.🤖 Generated with Claude Code