Running .sh scripts in Git Bash

Edvin picture Edvin · Apr 4, 2016 · Viewed 135.9k times · Source

I'm on a Windows machine using Git 2.7.2.windows.1 with MinGW 64.

I have a script in C:/path/to/scripts/myScript.sh.

How do I execute this script from my Git Bash instance?

It was possible to add it to the .bashrc file and then just execute the entire bashrc file.

But I want to add the script to a separate file and execute it from there.

Answer

intboolstring picture intboolstring · Apr 4, 2016

Let's say you have a script script.sh. To run it (using Git Bash), you do the following: [a] Add a "sh-bang" line on the first line (e.g. #!/bin/bash) and then [b]:

# Use ./ (or any valid dir spec):
./script.sh

Note: chmod +x does nothing to a script's executability on Git Bash. It won't hurt to run it, but it won't accomplish anything either.