How to execute .sh file on Windows?

You're on Windows CMD.EXE (from the error message). It uses a different syntax to execute commands. You'll need to use sh name.sh, assuming that you've got Cygwin or similar installed.

To clarify, Windows does not have a built-in utility to support .sh files. To run such, you'll need to install a third-party tool such as Cygwin.


Best solution in my opinion:

  • Download and install .git for Windows

  • Right click desktop and say "git bash here"

  • Execute your script like in unix

  • Done!

Caution: Many commands won’t work on windows! But still, a lot of the basic stuff will work.

If you need that script regularly you may want to create a shortcut (on your desktop e.g.):

  • Create a Shortcut to mintty.exe on your desktop

  • Edit properties of the shortcut and change the target (keep the path):

  • C:\Program Files\Git\usr\bin\mintty.exe" -h always /bin/bash -l -e 'D:\folder\script.sh'


You are trying to run a Linux command at the Windows Command Prompt.

On Linux the forward slash is a path separater. On Windows the backslash is a path separator and the forward slash generally indicates an argument.

Therefore, Windows thinks you are trying to run a command called "." and parsing it the argument "/name.sh". The correct convention would be ".\name.sh". Additionally Windows will automatically search the current directory for your command so you could just type "name.sh".

The next problem you will face is that Windows does not know what a sh script is, again this is a Linux thing. You could solve this by installing Cygwin if you really want or need to run a sh script.

However, judging by one of your previous comments you could just as well rename the script to name.bat and delete the "#!/bin/sh" line. Now you have a Batch file which Windows should understand. You can read more about batch files here.