Skip to content

Find sh on the PATH when running under Git Bash or MSYS2 on Windows - #2289

Merged
johnkerl merged 1 commit into
johnkerl:mainfrom
b84330808:windows-msys-shell
Nov 5, 2026
Merged

johnkerl merged 1 commit into
johnkerl:mainfrom
b84330808:windows-msys-shell

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

When MSYSTEM is set (Git Bash, MSYS2), GetShellRunArray returns /bin/sh. mlr.exe is a native Windows program and can't resolve that MSYS path, so everything that shells out fails from Git Bash:

$ mlr -n put 'end { print system("echo hi") }'
(error)
$ mlr --icsv --ojson --prepipe cat cat example.csv
mlr: fork/exec /bin/sh: The system cannot find the path specified.

Piped redirects (tee | "cat", $*) go through the same function. This looks sh up on the PATH instead (Git Bash and MSYS2 put their usr/bin there) and falls back to cmd /c if it isn't found. exec.LookPath returns an absolute path, which os.StartProcess in halfpipe.go needs.

Added a Windows-only test in pkg/platform that sets MSYSTEM and runs echo hello through the result; it fails before the change and passes after (skipped when there's no sh on the PATH). TestRunAllowShell in pkg/terminals/mcp also failed from Git Bash before this.

mlr regtest from Git Bash still needs the mlr path with forward slashes in the sh -c line; I left that out to keep this small.

With MSYSTEM set, GetShellRunArray returned "/bin/sh", which mlr.exe, a
native Windows program, cannot resolve. So system(), --prepipe and piped
redirects failed with "fork/exec /bin/sh: The system cannot find the path
specified." Look sh up on the PATH instead, falling back to cmd.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@johnkerl johnkerl left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you @b84330808 !!!

@johnkerl
johnkerl merged commit 1f9111c into johnkerl:main Nov 5, 2026
8 checks passed
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.

2 participants