Run bash script from Windows PowerShell

Viewed 283321

In cygwin, I could just do ./script.sh args, but this opens the script file in notepad in PowerShell.

What do I need to do have it execute?

6 Answers

You should put the script as argument for a *NIX shell you run, equivalent to the *NIXish

sh myscriptfile

It also can be run by exporting the bash and sh of the gitbash C:\Program Files\git\bin\ in the Advance section of the environment variable of the Windows Server.

In Advance section in the path var kindly add the C:\Program Files\git\bin\ which will make the bash and the sh of the git-bash to be executable from the window cmd.

Then,

Run the shell file as

bash shellscript.sh or sh shellscript.sh

As ghost21blade suggested, you can just use ./your_script.sh.

Also, you can add “C:\Program Files\Git\bin” to Path in User Environment Variables. In this case you will be able to do sh your_script.sh and bash your_script.sh

Simplest Way (Windows10)

./your_script.sh

But you have to enable script running on PowerShell See Here

Related