How to run bash script on Windows at system startup

Hello,

This topic may be a bit confusing but here is the story.
Let say we have a SH script startApp.sh 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:
sh startApp.sh
OR
./startApp.sh

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\startApp.sh

Or if the SH script takes parameter it could look like this:
"C:\Program Files\Git\bin\sh.exe" C:\tool\bin\startApp.sh 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\user.name\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