How to Run a .sh File on Windows (WSL or Git Bash)

Windows can’t run .sh shell scripts on its own, because they’re written for Linux and macOS shells like Bash. The best way to run one is with the Windows Subsystem for Linux (WSL): install it once with wsl --install, then run bash script.sh from the Linux terminal. For simple scripts, Git Bash is a lighter option. Both methods work on Windows 11 and Windows 10.

Method 1: Run a .sh file with WSL (recommended)

Install WSL

  1. Right-click the Start button and choose Terminal (Admin) (on Windows 10, Windows PowerShell (Admin)).
  2. Run wsl --install.
  3. Restart the PC when asked.
  4. After the restart, a Linux (Ubuntu by default) window opens. Create a Linux user name and password when prompted.

For more detail, see how to install WSL on Windows 11.

Run the script

  1. Open Ubuntu (or your Linux distribution) from the Start menu.
  2. Go to the folder that contains the script. Your Windows drives are under /mnt, so a script in your Downloads folder is at a path like /mnt/c/Users/YourName/Downloads. Use cd to move there.
  3. Run bash script.sh.

To run it as a program instead, make it executable once with chmod +x script.sh, then run ./script.sh.

Run it straight from PowerShell or Command Prompt

With WSL installed, open a terminal in the script’s folder and run wsl bash script.sh. WSL starts, runs the script in that folder, and returns you to Windows.

Method 2: Run a .sh file with Git Bash

  1. Download and install Git for Windows from git-scm.com. It includes Git Bash.
  2. Open the folder that contains the script in File Explorer.
  3. Right-click an empty area and choose Open Git Bash here (on Windows 11, select Show more options first).
  4. Run bash script.sh or ./script.sh.

Git Bash handles common commands well, but it isn’t a full Linux system. Scripts that use apt, Linux services, or Linux-only programs need WSL.

Fix common errors

  • “$’\r’: command not found” or “bad interpreter”: the script was saved with Windows line endings. In WSL, run sed -i 's/\r$//' script.sh, or install and run dos2unix script.sh. In code editors like VS Code, switch the line ending from CRLF to LF and save.
  • “Permission denied”: run chmod +x script.sh, or start it with bash script.sh instead of ./script.sh.
  • “No such file or directory”: check the path with ls. Linux paths are case-sensitive and use forward slashes.
  • A command in the script isn’t found: install the missing tool inside WSL, for example sudo apt install curl.
  • WSL is stuck or acting strangely: run wsl --shutdown in PowerShell and open it again. See how to reboot WSL.

Be careful with scripts from the internet

A shell script can delete files, change settings, or download other programs. Open it in a text editor and read it before running it, and only run scripts from sources you trust.

Frequently asked questions

Can I double-click a .sh file to run it?

Not by default. Windows doesn’t know which program to use. Running it from a WSL or Git Bash terminal is the reliable way.

What’s the Windows equivalent of a .sh file?

Batch files (.bat or .cmd) and PowerShell scripts (.ps1) do the same job natively on Windows, but the commands are different, so a .sh script can’t simply be renamed.

Do I need WSL 2?

wsl --install sets up WSL 2 by default on current Windows versions, which is what most people should use. See how to install WSL 2 on Windows 11.