T

How to Run Shell (.sh) Scripts on Windows

38 views · updated 2026-07-01 · published 2026-07-01 · by Hasarinda Manjula · Microsoft Windows Reading time: 3 min English සිංහල

Overview

Shell scripts (.sh files) automate tasks on Linux and macOS, but Windows does not run them natively. The best way to run them is the Windows Subsystem for Linux (WSL), which provides a real Linux environment inside Windows. This guide shows how to run .sh scripts using WSL and alternative tools.

Run Linux shell scripts on Windows using WSL or Git Bash.

Key Takeaways

  • Windows cannot run .sh scripts natively — use WSL or a Unix-style shell.
  • WSL gives you a genuine Linux environment with bash.
  • Git Bash and Cygwin are lighter alternatives for simple scripts.
  • Make a script executable with chmod +x and run it with ./script.sh.

What Are Shell (.sh) Files?

A .sh file is a text file containing commands for a Unix shell (usually bash). It is used to automate repetitive tasks. Because it targets the Linux/Unix shell, it needs a compatible shell environment to run on Windows.

1. Open PowerShell as administrator and run: wsl --install

2. Restart the PC and let the default Linux distribution (Ubuntu) finish setting up, creating a username and password.

3. Open the Linux terminal, then navigate to your script: cd /mnt/c/Users/YourName/Scripts

4. Make the script executable: chmod +x script.sh

5. Run it: ./script.sh

Note: Your Windows drives are available in WSL under /mnt/ — for example C: is /mnt/c.

Method 2 — Run With Git Bash

1. Download and install Git for Windows, which includes Git Bash.

2. Right-click in the folder containing your script and choose Git Bash Here.

3. Run the script with: ./script.sh (or bash script.sh).

Method 3 — Other Tools

  • Cygwin — provides a large collection of Unix tools and a bash shell on Windows.
  • MSYS2 — a Unix-like environment popular for building software.
  • Use these when you need Unix utilities without a full WSL setup.

How to Create a Shell Script

1. Open a plain-text editor such as Notepad or VS Code.

2. Start the file with the shebang line: #!/bin/bash

3. Add your commands, one per line.

4. Save the file with a .sh extension and (in WSL/bash) make it executable with chmod +x.

Frequently Asked Questions

Problem: Can I run shell scripts on Windows at all?

Solution: Yes — not natively, but through WSL, Git Bash, Cygwin, or MSYS2, which provide a compatible shell.

Problem: "Permission denied" when running ./script.sh.

Solution: Make the script executable first: chmod +x script.sh, then run ./script.sh.

Problem: The script runs but commands are "not found".

Solution: The script may use Linux tools not present in your shell. Use WSL for full Linux compatibility.

Problem: Line-ending errors (\r) appear.

Solution: The file has Windows line endings. Convert it with dos2unix, or save it with Unix (LF) line endings in your editor.

Conclusion

WSL is the most complete way to run shell scripts on Windows, giving you a real Linux environment. For quick scripts, Git Bash is a lightweight alternative — just remember chmod +x and ./script.sh.

</w:pBdr><w:spacing w:before="220" w:after="40"/></w:pPr><w:r><w:rPr><w:b/><w:bCs/><w:color w:val="0B5394"/><w:sz w:val="21"/><w:szCs w:val="21"/><w:rFonts w:ascii="Calibri" w:cs="Calibri" w:eastAsia="Calibri" w:hAnsi="Calibri"/></w:rPr><w:t xml:space="preserve">About TechHub

This guide is part of the TechHub Knowledge Base. For more step-by-step IT guides and support, visit techhub.com.lk.

Thanks for your feedback! 🙌

Read more

TechHub Assistant
Online · AI assistant
Thinking
⬇ Downloads 📦 Orders 🛒 Buy License 🎫 Create Ticket 🙋 Contact
AI-generated · may be inaccurate. Talk to a human