Mark Seemann
Mark Seemann

Reputation: 233150

Shell scripts with Git Bash 64-bit on Windows

I've installed Git Bash 2.5.1 64-bit on a fresh Windows 10 machine:

mark@Foo MINGW64 ~/Documents/FsCheck (master)
$ git --version
git version 2.5.1.windows.1

When I list the contents of a directory, I can see a shell script:

mark@Foo MINGW64 ~/Documents/FsCheck (master)
$ ls
appveyor.yml  build.cmd  build.sh*         Docs/
bin/          build.fsx  Contributors.txt  examples/  FsCheck.sln

(Some files and folders removed for clarity.)

Notice that the shell script build.sh has an asterisk after the extension. In the console, it's also coloured green, where other files are light grey. I haven't seen this before, so I don't know if it means anything.

When I try to run the script, I get an error message:

mark@Foo MINGW64 ~/Documents/FsCheck (master)
$ build.sh
bash: build.sh: command not found

Also, there's no tab completion for any of the build files.

How can I run the shell script from Git Bash?

Upvotes: 5

Views: 5693

Answers (2)

David A. Cobb
David A. Cobb

Reputation: 11

You can, of course, edit your PATH by adding ";." at the END of the current value. In mingw64_shell.bat do

SET PATH=%PATH%;.

Note: I'm looking at my MSYS2 installation, so you may need to look for the ".bat" file that launches bash. The biggest security problem with the WINDOWS default path that had "." in front of the path is that it allows a user to over-ride a system executable -- that would make your scripts do some weird stuff, especially if you import them from someone else.

Upvotes: 1

pacholik
pacholik

Reputation: 8972

You probably have ls aliased to ls -F. So when an trailing asterisk appears that means that the file is executable.

In POSIX systems, you can't directly execute files in current directory (for safety reasons). If you want to, you can use this trick:

./build.sh

Upvotes: 7

Related Questions