Shell scripts are a piece of code written in plain text but have the “.SH” file extension. These are usually used to automate tasks and execute Linux or Unix packages. These are written in Bash and start with “#! /bin/sh“. You do not need to install a Linux or Unix distribution alongside your Windows operating system to run a shell script. In this article, we’ll show you how to run a shell script on a Windows PC.

What are Shell (.SH) Files

The Linux/Unix operating system uses shell or .SH script files to perform certain tasks. In comparison, it can be substituted by Windows batch files for the Windows operating systems, which are used to execute commands on a computer. The Batch language is a simple and interpreted programming language, unlike C++ or C#. However, you do not have to translate a shell script file to batch to perform similar tasks on a Windows computer, as you do on a Linux PC. There are different methods to run the same .SH file on a Windows computer as on a Linux system. Let us show you how to run a shell file on a Windows PC.

Run Shell Script (.SH) File on Windows

There are both native and third-party methods to run shell files on a Windows computer. You can use Cygwin, or a third-party tool of your choice, to run a shell script on Windows OS. Alternatively, you can install the Windows Subsystem for Linux feature on Windows and then execute the shell script file through it. Below you’ll find the methods to run the file using both methods.

Run Shell Script File using Windows Subsystem for Linux (WSL)

This section has been divided into 3 steps to make the process easier to understand. You must do the following 3 things to run a shell script file in the given order: Note: If you are performing these steps on a Virtual Machine, then you will need to enable Nested Virtualization.

Install WSL

Use the following steps to install WSL on your computer: Once the computer restarts, it is time to install a Linux distro. The wizard will now install WSL.

Install a Linux Distribution

Use the following steps to install a Linux distribution: Now, the next step is to simply run the shell script file. Note down the name of the distro you want to install. The distro will now begin to download and install.

Run the Shell Script File

Follow the simple steps below to run the shell script file on a Windows PC: This is how you run a shell script (.SH) file on a Windows computer using WSL. If this seems like a lengthy process for you, then you can also use the alternative method given below.

Run Shell Script File using Third-Party Tools

You can also run a shell script file on a Windows computer using a third-party tool. In the steps below, we have used Cygwin. Follow these steps to run a .SH file on a Windows PC: These are the two methods to run shell script files (.SH) on a Windows PC. Of course, there are many other third-party tools available that allow you to run Linux and Unix files on a Windows computer. Note: In Cygwin, the syntax to change the directory is different from Command Prompt or PowerShell. Use the following command syntax and example in the image to change your directory in Cygwin.