Using Bash scripts from Windows

For certain use cases, it’s feasible to run a Bash script from within Windows. The obvious way to do this is via Windows Subsystem for Linux. However, there is a third way to run Bash scripts from within Windows itself, not needing Windows Subsystem for Linux. In this example, we rely on the Bash shell installed with Git on Windows.

The trick is to start the Bash script you want to run from Linux or Windows with the shebang (first line of Bash script file):

#!/bin/bash; C:/Program\ Files/Git/user/bin/sh.exe

This tells the shell (Linux or Windows) to first try /bin/bash which is a Unix-like path, and then try the Git Bash shell on Windows. If Python is on your Windows Path, you can even use Bash scripts that also invoke Python scripts. This is very handy in general.