How to Execute SH or Shell Script Files on Windows 10 and 11
Shell scripts (with the .sh extension) are most commonly used on Linux and macOS systems to automate tasks through command-line instructions. However, many developers and IT professionals also need to run shell scripts on Windows 10 or Windows 11 for testing, cross-platform development, or automation purposes. Fortunately, modern versions of Windows include several built-in and third-party methods to execute these scripts easily.
This guide explains what .sh files are, how to run them in Windows 10 or 11, and provides step-by-step instructions for each method, including using Windows Subsystem for Linux (WSL), Git Bash, Cygwin, and Windows PowerShell.

What Is a .sh File?
A .sh file is a Shell script, which is a text file that contains a sequence of commands for Unix or Linux-based systems. These scripts are executed by the Bash shell (Bourne Again Shell) or similar interpreters.
The primary purpose of shell scripts is to automate repetitive tasks, such as system updates, file operations, or running programs in sequence.
For example, a simple .sh script might look like this:
On Linux or macOS, you can easily execute this script from the terminal. However, since Windows does not natively support the Bash shell environment, you need special tools or features to run it.

Can You Run .sh Files on Windows?
Yes, you can. With the introduction of Windows Subsystem for Linux (WSL) and other compatible utilities, running shell scripts on Windows 10 or 11 is now straightforward.
Depending on your needs, you can choose between several methods, such as:
-
Using Windows Subsystem for Linux (WSL)
-
Using Git Bash
-
Using Cygwin
-
Using PowerShell (with Bash emulation)
Let’s go through each method in detail.
Method 1: Run .sh Files Using Windows Subsystem for Linux (WSL)
Step 1: Install WSL
WSL allows you to run a real Linux environment directly inside Windows without needing a separate virtual machine or dual boot setup.
-
Open Command Prompt or PowerShell as Administrator.
-
Type the following command and press Enter:
-
This command installs WSL with the default Linux distribution (usually Ubuntu).
-
Restart your computer when prompted.
Step 2: Open Your Linux Distribution
Once installation is complete:
-
Open the Start Menu and search for Ubuntu (or your installed Linux distribution).
-
Launch it, and a terminal window will appear.
Step 3: Navigate to the Folder Containing Your .sh File
Use the cd command to go to the directory where your .sh script is located. For example:
(Windows drives are mounted under /mnt in WSL.)
Step 4: Make the Script Executable
Before running the script, grant execution permission:
Step 5: Run the Script
Now, execute your shell script by typing:
If your script runs successfully, you’ll see the output directly in the WSL terminal.
Method 2: Run .sh Files Using Git Bash
If you don’t want to install a full Linux subsystem, Git Bash is a lightweight and simple alternative.
Step 1: Download and Install Git Bash
-
Visit the official Git website: https://git-scm.com/downloads
-
Download the version for Windows and install it using the default settings.
Step 2: Open Git Bash
After installation, right-click anywhere on your desktop or in a folder and select “Git Bash Here” from the context menu.
Step 3: Run the .sh File
Navigate to the directory where your .sh file is saved:
Then execute the script:
Git Bash provides a Unix-like terminal on Windows, making it an excellent choice for developers familiar with Linux commands.
Method 3: Run .sh Files Using Cygwin
Cygwin is another tool that brings a Linux-like environment to Windows. It offers more comprehensive compatibility with Unix tools than Git Bash.
Step 1: Download and Install Cygwin
-
Go to the official website: https://www.cygwin.com/
-
Download the setup executable for Windows (32-bit or 64-bit).
-
Run the installer and follow the prompts. During installation, you can select additional packages such as
bash,gcc, ormakeif needed.
Step 2: Launch Cygwin Terminal
After installation, open the Cygwin Terminal from the Start Menu.
Step 3: Navigate to the Script Location
Use the cd command to access the folder containing your script. Example:
Step 4: Run the .sh File
Cygwin executes shell scripts in a near-native Linux environment, making it suitable for users who need to run more complex or Unix-dependent scripts.
Method 4: Run .sh Files Using PowerShell
While PowerShell is primarily used for Windows scripting (.ps1 files), you can use it to run Bash commands if you have WSL installed.
Step 1: Open PowerShell
Press Windows + X and select Windows PowerShell (or Windows Terminal in Windows 11).
Step 2: Run the Script via WSL
If WSL is installed, use this syntax:
This command runs your script directly through WSL from PowerShell, combining both Windows and Linux functionality.
Method 5: Convert the Script for Windows Batch
If you prefer not to install extra tools, you can manually convert simple .sh commands into .bat files (Windows Batch scripts).
Example Conversion
Original .sh script:
Equivalent .bat script:
This method is only suitable for basic scripts, as many Linux commands don’t have direct Windows equivalents.
Troubleshooting Common Issues
1. “Permission Denied” Error
Make sure your script is executable by running:
2. “Command Not Found” Error
Some commands used in your script may not exist in your selected environment. Ensure you have installed the necessary packages or tools (for example, apt install in WSL).
3. Path Errors
When running scripts from Windows drives in Linux-based environments, always use the /mnt or /cygdrive prefixes (e.g., /mnt/c/Users/...).
Which Method Should You Choose?
-
For Developers or Power Users: WSL is the best option, offering full Linux compatibility.
-
For Simple Tasks: Git Bash is lightweight and easy to use.
-
For Complex Linux Environments: Cygwin provides extensive Unix command support.
-
For Occasional Use: PowerShell with WSL commands is convenient without switching terminals.
Conclusion
Running .sh or shell script files in Windows 10 or 11 has become easier than ever. Thanks to tools like WSL, Git Bash, and Cygwin, Windows users can now execute Linux shell scripts directly without needing dual boot or virtualization.
Whether you’re a developer testing scripts or a power user automating tasks, choosing the right method depends on your workflow and needs.
If you want seamless Linux integration and maximum compatibility, Windows Subsystem for Linux (WSL) is the best choice. For quick execution or basic scripts, Git Bash or Cygwin can handle the job efficiently.
