How to run bash script on Windows at system startup


This topic may be a bit confusing but here is the story.
Let say we have a SH script and we would like to run it on Windows because there is no equivalent BAT script available. In general if you want to run bash script you need some sort of bash command line interpreter. For example you can install Git bash:

Then it's simply - open Git bash and cd to the target script directory and run it manually by invoking the command:

Now if you would like to run it without touching the command line you can create a windows shortcut to run the bash script. In the shortcut command you also need to provide a bash program that will execute the script - in this case it will be Git bash. So the shortcut underlying command will be something like this:
"C:\Program Files\Git\bin\sh.exe" C:\tool\bin\

Or if the SH script takes parameter it could look like this:
"C:\Program Files\Git\bin\sh.exe" C:\tool\bin\ start

That's pretty cool :) Now if you would like to have it run at windows startup you place this shortcut in the menu start startup folder. On Windows 7 for example it's in the following location:
C:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Just copy your shortcut there and you are done.

Hope that will help in some cases.

No comments:

Post a Comment