7

From what I understand bin\bash.exe invokes usr\bin\bash.exe I guess with some options to help manage windows paths but can't find any documentation to indicate that.

All I know is my scripts seem not to work as expected if I have my environment set to use Git\usr\bin\ rather than Git\bin.

A new dev box seems to have this setup:

where bash

C:\Windows\System32\bash.exe

C:\Program Files\Git\usr\bin\bash.exe

I can understand wsl being top but can't understand the second entry if bin/bash.exe is the one I am supposed to use?

Alastair Taylor
  • 345
  • 1
  • 3
  • 10
  • Use for what? In general? – CervEd May 27 '21 at 09:32
  • Possible duplicate of [In the install path of Git for Windows, what's the difference between ./git-bash.exe and bin/bash.exe and bin/sh.exe?](https://stackoverflow.com/questions/53980686/in-the-install-path-of-git-for-windows-whats-the-difference-between-git-bash) – OfirD Oct 01 '21 at 11:55

2 Answers2

5

%windir%\system32\bash.exe = inline bash shell hosted by whatever windows subsystem for linux [ wsl ] environment you have enabled using microsoft store | windows subsystem for linux | | install. An alternative but essentially same result as the separate window that start menu shortcut %windir%\system32\wsl.exe ~ -d Ubuntu launches.

%programfiles%\git\bin\bash.exe -> %programfiles%\git\usr\bin\bash.exe + some automatically injected arguments = inline [ main stdin/stdout ] bash shell provided by git layered on top of windows cmd.exe command prompt environment

%programfiles%\git\git-bash.exe = windows app [ winmain ] bash shell provided by git layered on top of windows cmd.exe command prompt environment

myusrn
  • 1,050
  • 2
  • 15
  • 29
  • Thanks for the reply! As I mentioned my scripts only seem to work if I use: "C:\Program Files\Git\bin\bash.exe" - so I guess I need to understand what these "+ some automatically injected arguments" are... Is this documented anywhere? Did look on the git-for-windows github but couldn't see anything. – Alastair Taylor Sep 17 '19 at 14:45
  • 1
    I don't know. I ran `%programfiles%\Git\bin\bash.exe` and then under process details looked at command line and i see that it spawns a `%programfiles%\Git\bin\..\usr\bin\bash.exe` w/o any command line arguments so the document i saw referring to "+ some automatically injected arguments" is perhaps referring to internally defined arguments in that exe given its 1918KB vs the bin\bash.exe that is 44KB. – myusrn Sep 18 '19 at 16:13
  • On my system attempting to running `%programfiles%\Git\usr\bin\bash.exe` directly produces output `bash: cut: command not found` and attempts to use `printenv`, in effort to compare environment differences launching this way vs using `Git\bin\bash.exe`, produces `bash: printenv: command not found`. – myusrn Sep 18 '19 at 16:22
  • 1
    Running the alternative `%programfiles%\Git\bin\git-bash.exe` i see that it spawns `usr\bin\mintty.exe --nodaemon -o AppID=GitForWindows.Bash -o AppLaunchCmd="%programfiles%\Git\git-bash.exe" -o AppName="Git Bash" -i "%programfiles%\Git\git-bash.exe" --store-taskbar-properties -- /usr/bin/bash --login -i` to setup the new command window followed by `%programfiles%\Git\usr\bin\bash.exe`. – myusrn Sep 18 '19 at 16:22
  • `layered on top of windows cmd.exe command prompt environment` is it? It runs `bash.exe` on top of `mintty.exe` but does it also involve `cmd.exe`? – CervEd May 27 '21 at 09:36
  • @CervEd when i launch & "$env:programfiles\git\bin\bash.exe" and then do a process dump i see no instances of & "$env:programfiles\git\usr\bin\mintty.exe" running. If i execute & "$env:programfiles\git\usr\bin\mintty.exe" i get a gui popup that lets me select "msys2", "mingw-w64 32 bit" and "mingw-w64 64 bit" type of bash shell and after that is launched i do still see instances of & "$env:programfiles\git\usr\bin\mintty.exe" running. So it appears mintty.exe is involved depending on how you launch the git install provided bash shell experience. – myusrn May 28 '21 at 18:19
  • yes, `bash.exe` doesn't run `mintty` only `git-bash.exe`, it was `cmd.exe` I was wondered about – CervEd May 29 '21 at 11:32
2

So it appears that:

"C:\Program Files\Git\usr\bin\bash" -li

yields:

Me@MYPC MSYS /usr/bin

and

"C:\Program Files\Git\bin\bash" -li

yields:

Me@MYPC MINGW64 /usr/bin

So to my eyes that implies the EXE are compiled differently.

But in my case the issues I was having with my scripts was purely down to the PATH each exe sets up:

For

"C:\Program Files\Git\usr\bin\bash.exe"

$ where FIND C:\Windows\System32\find.exe C:\Program Files\Git\usr\bin\find.exe

Whereas:

"C:\Program Files\Git\bin\bash.exe"

$ where FIND C:\Program Files\Git\usr\bin\find.exe C:\Windows\System32\find.exe

So my script in the former case was failing with a

FIND: Parameter format not correct

as it wasn't finding the correct version of find.

Alastair Taylor
  • 345
  • 1
  • 3
  • 10