How to Run .sh File in Windows – Linux Hint

The “sh” file is a scripting script file with a “.sh” extension. Contains system programs that can run on the Unix-based system or in the UNIX shell. A sh file can be opened in many text editors like notepad, Apple terminal. However, this scripting file is typically run on the command line using the “bash” or “sh” command.

The following article will show the method to run a .sh file in Windows.

How to configure WSL in Windows?

The .sh file cannot be run directly at the Windows command prompt or PowerShell. Therefore, to run the .sh file on Windows, it is necessary to enable “Windows Subsystem for Linux” (WSL) on the system.

Follow the steps provided below to enable WSL on Windows system.

Step 1: Turn on developer mode In the first step, open the Windows “Settings” by looking for it in the “Start” menu

:

Go to the “Update and Security” settings:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/08/How-to-Run-.sh-File-in-Windows-2.png”

alt=”

” /> Open the “

For Developers” window and enable “Developer Mode

“:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/08/How-to-Run-.sh-File-in-Windows-3.png” alt=”” />

Step 2: Enable WSL

in Windows When typing “Windows Features”

in the search field, select the “Turn Windows features on or off” option:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/08/How-to-Run-.sh-File-in-Windows-4.png” alt=”” />

When you do this, the “Windows Features” wizard will appear on the screen. Check the “Windows Subsystem for Linux” checkbox and press the

“OK” button:

This operation will start enabling WSL in Windows:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/08/How-to-Run-.sh-File-in-Windows-6.png”

alt=”” />

Then restart the system for the changes to take effect by pressing the “Restart Now” button:

At this point, we have enabled WSL in Windows. We will now install Linux-compatible tools that help us execute Linux commands on Windows.

Step 3: Install Ubuntu

Linux

Tool Go to “Microsoft Store” by searching for it in the “Start” menu:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/08/How-to-Run-.sh-File-in-Windows-8.png” alt=”” />

Search for “Linux application” in the search bar. Scroll down, select

and open Ubuntu 22.04 LTS: Click the “Get” button to install Ubuntu 22.04 LTS terminal on Windows:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/08/How-to-Run-.sh-File-in-Windows-10.png”

alt=”” />

Press the “Open” button to open and configure Ubuntu 22.04 LTS on Windows:

Step 4: Configure the initial

Ubuntu

setup The Ubuntu terminal will open on the screen. Set the username and password:

The output given above shows that we have successfully configured WSL in Windows. Let’s go ahead to create a .sh file.

How to create a .sh file in Windows?

To create a .sh file in Windows by using the command line, follow the steps provided

: Step

1: Open Windows Command Prompt

Search for “CMD” in the “Start” menu and open the command prompt

:

<img src

=”https://linuxhint.com/wp-content/uploads/2022/08/How-to-Run-.sh-File-in-Windows-13.png” alt=”” />

Step 2: Enable

the Linux

command line interface Enable the Linux command line interface by using the “bash” command. Then, switch to the “Documents” directory for file creation. You can also

create a .sh file in the currently open directory:

Step 3: Create .sh file Now, we will create a .sh file called “sum.sh” file with the help of nano editor:

Paste the code provided below into the opened file, press “Ctrl + O” to save the file and exit the nano editor by pressing “Ctrl + X“:

We have created a sum.sh file using the Windows command prompt. Let’s take a look at the method to run the .sh file.

How to run .sh file in Windows?

To run a .sh file in Windows, use the “bash” command and specify the name of the file. We will run our “sum.sh” file using the following command

:

The output given below indicates that we have successfully executed

the .sh file in Windows:

We have compiled the approaches to allow WSL to create and run the .sh file in Windows.

Conclusion To run the .sh file on Windows, you need to enable the WSL feature. After enabling WSL, download the tool that supports Linux command line, as we have downloaded the “Ubuntu 22.04 LTS” on Windows. Then, create a .sh file and run it using the “$bash sum.sh” command in the command prompt. We have demonstrated the method to create and run .sh files on Windows using WSL.