Repository navigation
Description
Drop-in report: $0 for PATH-resolved scripts, PATH ordering vs Git Bash, and stubbed programmable completion
First of all — great project. On this machine gash starts in ~10 ms vs ~250 ms for Git Bash, and the language-level compatibility is genuinely impressive (details at the end). This issue collects what currently blocks using gash as a real Git Bash replacement, with minimal reproducers. All of it was measured on the same machine, same PATH, same scripts, gash vs C:\Program Files\Git\bin\bash.exe.
Environment
- gash 0.2.0 (single-file install),
BASH_VERSION 5.2.37(1)-release - Windows 10 19045, Git for Windows (its bash is 5.3.15)
- Microsoft Coreutils is installed and present on the inherited Windows PATH, which makes some PATH issues below easier to see (noted where it matters)
- Method: 71 differential scripts run from identical sandboxes under both shells, plus interactive checks through a PTY (
-i,-l, Tab, Ctrl+C, history)
Result: 52/71 scripts byte-identical after normalising paths/PIDs/versions. Almost every remaining difference traces back to the three root causes below; the rest are in "Smaller issues".
1. $0 is the bare command name for scripts resolved through PATH
This is the most impactful one: it breaks every POSIX launcher that locates itself via $0, which includes Gradle, Maven and npm's generated sh shims.
$ mkdir -p /tmp/bin
$ printf '#!/bin/sh\necho "0=[$0]"\n' > /tmp/bin/shim
$ PATH=/tmp/bin:$PATH shim
0=[shim] # gash 0.2.0
0=[/tmp/bin/shim] # Git BashReal-world consequences (all reproduced here, Git Bash works in each case):
gradle --version→
Error: Unable to access jarfile D://lib/gradle-gradle-cli-main-9.9.0.jar
Gradle's POSIX launcher doesAPP_HOME=$(cd -P "${APP_HOME:-./}.." && pwd), so with$0=gradle(dirname→.)APP_HOMEbecomes the parent of the current directory, and the jar path is garbage. The exact path depends on the cwd, which is why the same command fails with different.../lib/...paths in different folders.mvn -v→
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
(samedirname "$0"→MAVEN_HOMEmechanism).- npm-generated shims:
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")resolves to., so a CLI likehunk --versiondoes
Error: Cannot find module 'C:\Users\<user>\node_modules\hunkdiff\bin\hunk.cjs'
instead of loading the module next to the shim. - Only the direct-path invocation works:
/c/.../gradle --versionandgradle.bat --versionare fine. This hits Gradle/Maven distributions, SDKMAN-managed candidates that ship a POSIX launcher, and every npm-installed CLI.
Also affected: BASH_SOURCE[0] for such scripts (same bare name), which breaks the very common cd "$(dirname "${BASH_SOURCE[0]}")" idiom.
Root cause: in src/exec.rs, run_script_inproc() does
child.arg0 = argv[0].clone();
child.source_name = argv[0].clone();argv[0] is the word as typed. Bash sets $0 to the resolved path when the script comes from a PATH lookup (and to the word as typed when the user passes a path explicitly, e.g. ./script.sh — gash already matches that case). Suggested fix: for Resolved scripts, set arg0/source_name to res.path (in MSYS form) when the command was found through PATH.
2. PATH keeps Windows directories ahead of Git's /usr/bin
Git Bash puts /usr/bin (and ~/bin) before C:\Windows\System32. gash only prepends /usr/bin when it is absent; when Git's usr\bin is already in the inherited Windows PATH — which is the normal Git for Windows setup, e.g. C:\Program Files\Git\usr\bin — it stays wherever Windows put it, and Windows tools win:
| Command | gash resolves to | Git Bash resolves to | Observable result under gash |
|---|---|---|---|
bash --version |
C:\Windows\System32\bash.exe (WSL) |
/usr/bin/bash |
WSL ... execvpe(/bin/bash) failed: No such file or directory; every script that re-invokes bash breaks |
timeout 1 echo hi |
C:\Windows\System32\timeout.exe |
/usr/bin/timeout |
ERROR: Invalid syntax. Default option is not allowed more than '1' time(s)., rc=1 instead of hi |
tar |
C:\Windows\System32\tar.exe (bsdtar) |
/usr/bin/tar (GNU tar) |
different flag set/behaviour |
sort, find, head, rm, ls |
C:\Program Files\coreutils\bin\* (uutils) |
/usr/bin/* |
find . prints .\file instead of ./file; rm -rf on a tree containing a directory symlink fails with Permission denied; head -c 4096 /dev/urandom fails with head.exe: cannot open 'C:/Program Files/Git/dev/urandom' |
ssh, unzip |
Windows/choco builds | MSYS/GNU builds | subtle differences in config/paths/version output |
Root cause: in src/main.rs the PATH setup only prepends <prefix>/bin and /usr/bin when they are not present:
let present = parts.iter().any(|p| p == &w || ...);
if !present { front.push(w); }An inherited C:\Program Files\Git\usr\bin is already in parts, so it is not moved to the front.
Suggested fix: mirror /etc/profile — take the existing <prefix>/bin, /usr/bin, /bin (and ~/bin for login shells) entries out of the list and re-insert them at the front, de-duplicated. The existing own_shell_dir() block already does something similar for the "gash installed as bash.exe" case.
That single change fixes bash → WSL, timeout, tar, find, head /dev/urandom, rm -rf + directory symlinks, and makes command -v agree with Git Bash.
3. complete, compopt and bind are silent no-ops
src/builtins.rs has:
"complete" | "compopt" | "bind" => Ok(0),So every completion registration and every readline key binding in ~/.bashrc is accepted (rc 0, no warning) and thrown away:
# rc file
_f() { COMPREPLY=(alpha); }
complete -F _f mycmd
$ mycmd al<TAB>
$ mycmd al # gash: bell, no completion; `complete -p mycmd` prints nothing
$ mycmd alpha # Git BashThis is what makes Gradle and SDKMAN completion "disappear" after switching, even though ~/.bashrc is read and the functions are defined:
gradle-completion.bash:complete -F _gradle gradle/gradle.bat/gradlew/gradlew.bat- SDKMAN
contrib/completion/bash/sdk:complete -o default -F _sdk sdk bindfrom.bashrc(history-search etc.) is lost the same way
To be clear: startup files themselves work — in an interactive shell (gash, gash -i, gash -l) LANG, SDKMAN_DIR, sdk, aliases and _gradle are all present (verified). The "no completions" symptom is entirely #3. What does differ from a plain "bash" experience is gash -c not reading rc files (same as bash), so tools/agents that call gash -c see none of the SDKMAN/JAVA_HOME/proxy environment.
Suggestion: implement at least complete -F/-p/-r (function-based completion covers Gradle, SDKMAN, git-completion) and print a one-time warning for unsupported options instead of silently ignoring them.
Smaller issues
type -areturns only the first PATH match.type -a echo→echo is a shell builtin+ one external hit; bash lists the builtin plus every PATH match. Same fortype -a ls.- Error message for E2BIG is the raw localized Windows text.
python ... "$(cat 40k-file)"fails in both shells, but gash printsИмя файла или его расширение имеет слишком большую длинуwhile bash printsArgument list too long. Please mapERROR_FILENAME_EXCED_RANGE/E2BIG to the POSIX wording (and keep messages English). ( kill -INT $$ )does not reach the parent shell.trap 'echo INT' INT; ( kill -INT $$ )runs the trap in bash but not in gash; directkill -INT $$works.declare -a/declare -Adon't list bash's internal arrays. bash printsBASH_ARGV,BASH_SOURCE,BASH_LINENO,BASH_ALIASES,BASH_CMDS,DIRSTACK,GROUPS; gash prints onlyBASH_VERSINFOandPIPESTATUS. Scripts that introspectdeclare -aoutput notice.- Prompt is printed twice under a PTY (
$ $ echo hi), while Git Bash prints it once. Cosmetic; may be an artifact of the winpty-based harness, but it reproduced consistently for every line. realpath/readlink -fprint Windows paths (C:\...), which is documented, but the commoncd "$(dirname "$(realpath "$0")")"idiom then produces a mixed path. Consider emitting MSYS form by default (or an option).
Already fixed on main, but not in the 0.2.0 release
These reproduce with the shipped 0.2.0 binary, so a new release would remove them from the list:
pwd -Wreturns/d/...instead ofD:/...cmd //c echo hiopens an interactivecmdinstead of running the command (//cis not unescaped)MSYS_NO_PATHCONV=1 cmd .../MSYS2_ARG_CONV_EXCL=* cmd ...as a command prefix is ignored (exported variables work)
This matches merged PRs #10 and #11. Please consider cutting a 0.2.1/0.3.0 so the winget/zip users get them.
What already works (for context)
Verified matching Git Bash in this run:
- Quoting, IFS/splitting, all parameter expansions, indexed/associative arrays, arithmetic (bases,
**, assignment ops),[[ ]]incl.=~+BASH_REMATCH,test, globbing (nullglob,dotglob,globstar, brace expansion) - Pipelines,
pipefail,!, subshells,$(),<( )/>( ), redirections incl.exec 3>, here-docs (quoted/indented) and here-strings,set -euo, traps (EXIT/ERR),read/mapfile/getopts,source,eval,printf %q/%b,select-free loops,casewith;&/;;& - Job basics:
&,wait,jobs,kill, Ctrl+C (rc 130), history expansion (!!), CRLF scripts - Windows integration:
/c/...↔C:/...conversion for native programs,MSYS_NO_PATHCONV/MSYS2_ARG_CONV_EXCLwhen exported,/dev/nullredirections, symlink creation/traversal (ln -s, sdkman-stylecurrent→ version), hard links, long argument lists - Tools that behave identically: git (init/add/commit/log/diff/status/ls-files/check-ignore), java/javac, python (incl.
python -m venv+source .../activate+deactivate), node (stdin, argv), curl, gh, jq, rg, zip/unzip, make, gcc, ssh
Minimal reproducers (copy-paste)
# 1. $0
mkdir -p /tmp/bin && printf '#!/bin/sh\necho "0=[$0]"\n' > /tmp/bin/shim
PATH=/tmp/bin:$PATH shim # gash: 0=[shim] bash: 0=[/tmp/bin/shim]
# 1b. real-world: any Gradle/Maven/npm install on PATH
gradle --version # gash: Unable to access jarfile .../lib/gradle-gradle-cli-main-*.jar
mvn -v # gash: Could not find or load main class ...classworlds...
# 2. PATH ordering
command -v bash # gash: /c/Windows/system32/bash bash: /usr/bin/bash
bash --version # gash: WSL ... execvpe(/bin/bash) failed
timeout 1 echo hi # gash: Windows TIMEOUT.EXE error bash: hi
head -c 4096 /dev/urandom | wc -c # gash: 0 + error bash: 4096
# 3. completion
printf '_f() { COMPREPLY=(alpha); }\ncomplete -F _f mycmd\n' > rc
gash --rcfile rc # type: mycmd al<TAB> -> no completion, `complete -p mycmd` prints nothingHappy to test a fix, or split this into separate issues if that is easier to track.
Activity
magicprinc commentedon Nov 9, 2026
Full accounting of the differential run (71 scripts)
For completeness: 52 of 71 matched byte-for-byte; here is how the other 19 are classified, so nothing from the testing is left unreported.
Root cause 1 —
$0of PATH-resolved scripts030-maven—mvn -vfails with the classworldsClassNotFoundException(samedirname "$0"mechanism; Gradle and npm shims are reproduced in the body).Root cause 2 — PATH ordering
020-env— a childbash -cstarts WSL bash and fails.026-msys-tools—find .prints.\f.txtinstead of./f.txt.038-links—rm -rffails on a tree containing a directory symlink (Permission denied).046-type-hash—command -v ls,type -a, etc. point at coreutils instead of/usr/bin.060-stdin-binary—head -c 4096 /dev/urandomfails withhead.exe: cannot open '.../dev/urandom'.068-timeout—timeout 1 echo hihits WindowsTIMEOUT.EXE.086-type-a—type -areports only the first PATH match (smaller issue 1).Same root cause, already fixed on
main(reproduce on the 0.2.0 release only)021-pathconv,022-spaces,075-redirect-native—cmd //c(PR Pass //-escaped switches to native programs with one slash, as MSYS does #11).042-pwd-cd—pwd -W(PR Honor MSYS_NO_PATHCONV given as a command prefix, and add pwd -W #10).MSYS_NO_PATHCONV=...command-prefix probe.By design / documented, not defects
006-arrays—declare -adoes not listBASH_ARGV/BASH_SOURCE/… (smaller issue 4).013-subshell-cmdsub— process substitution runs to completion first (README documents temp files instead of pipes).023-unicode—${#s}counts bytes whenLANGis unset; identical to Git Bash with a UTF-8LANG(verified).048-vars—BASH_VERSION5.2.37 vs 5.3.15,$BASHpoints at gash itself.076-login-checks—SHELLis gash's own path.078-which-realpath—realpath/readlink -fprintC:\...(README documents this).081-long-args— both shells reject >32k arguments; only the wording differs (localized Windows text, smaller issue 2).071-ctrl-signals— only the( kill -INT $$ )subshell form differs (smaller issue 3).Interactive probes (outside the 71):
completeis a no-op (#3), prompt is drawn twice, Ctrl+C returns 130 and!!works, startup files (~/.bashrc,~/.bash_profile) are read and export their environment.