How to Execute SH or Shell Script Files on Windows 10 and 11

October 21, 2025

0
(0)

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.

Shell Script Files

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:

#!/bin/bash
echo "Hello, World!"

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.

Shell Script Files2

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.

  1. Open Command Prompt or PowerShell as Administrator.

  2. Type the following command and press Enter:

    wsl --install
  3. This command installs WSL with the default Linux distribution (usually Ubuntu).

  4. Restart your computer when prompted.

Step 2: Open Your Linux Distribution

Once installation is complete:

  1. Open the Start Menu and search for Ubuntu (or your installed Linux distribution).

  2. 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:

cd /mnt/c/Users/YourUsername/Desktop

(Windows drives are mounted under /mnt in WSL.)

Step 4: Make the Script Executable

Before running the script, grant execution permission:

chmod +x filename.sh

Step 5: Run the Script

Now, execute your shell script by typing:

./filename.sh

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

  1. Visit the official Git website: https://git-scm.com/downloads

  2. 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:

cd /c/Users/YourUsername/Desktop

Then execute the script:

bash filename.sh

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

  1. Go to the official website: https://www.cygwin.com/

  2. Download the setup executable for Windows (32-bit or 64-bit).

  3. Run the installer and follow the prompts. During installation, you can select additional packages such as bash, gcc, or make if 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:

cd /cygdrive/c/Users/YourUsername/Desktop

Step 4: Run the .sh File

bash filename.sh

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:

wsl bash /mnt/c/Users/YourUsername/Desktop/filename.sh

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:

#!/bin/bash
echo "Cleaning temporary files..."
rm -rf /tmp/*

Equivalent .bat script:

@echo off
echo Cleaning temporary files...
del /q/f/s %TEMP%\*

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:

chmod +x filename.sh

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.

How useful was this guide?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments