Why can't Git Bash run my executable?

WindowsGitBashMingw W64Msys2

Windows Problem Overview


I am on git-for-windows Git Bash. I can't run an executable on the command line:

Pedr@Abc-07 MINGW64 /c/dev
$ ls sqlite3.exe
sqlite3.exe*

Pedr@Abc-07 MINGW64 /c/dev
$ sqlite3
bash: sqlite3: command not found

Why is it so?

Windows Solutions


Solution 1 - Windows

To run a program in the current directory in bash, you put ./ in front of it. So in your case:

$ ./sqlite3.exe

When you run sqlite3, bash will look for a program with exactly that name in all directories of the PATH environment variable, which by default includes standard locations for executables like /usr/local/bin but not your current directory. See here for more info on that.

Solution 2 - Windows

It's because you're under a is a runtime environment for gcc, that give you support to binaries native under Windows, but you can run any exe as shell using ./ (local execute) Take a look to documentation of this tool: http://sourceforge.net/p/mingw-w64/wiki2/FAQ/

Solution 3 - Windows

Your PATH is missing ./. Add it to your .profile file in the home directory (/c/Users/username):

$ cd
$ pwd
/c/Users/username
$ echo 'PATH=$PATH:./' >> .profile

Restart bash session and voilà! Now echo $PATH should output :./ as the last item. Note that you definitely need to add it as the last item for security (e.g. against malicious ls.exe).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPedro OSView Question on Stackoverflow
Solution 1 - WindowsNattgewView Answer on Stackoverflow
Solution 2 - WindowsAlvarovaView Answer on Stackoverflow
Solution 3 - WindowseppView Answer on Stackoverflow