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 & 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 activate the “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:
When you do this, the “Windows Features” wizard will appear on the screen. Check the “Windows Subsystem for Linux” checkbox and press the
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
Tool Go to the “Microsoft Store” by searching for it in the “Start” menu:
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:
Press the “Open” button to open and configure Ubuntu 22.04 LTS on Windows:
Step 4: Configure the initial setup of
The Ubuntu terminal will open on the screen. Set the username and password:
The output given above shows that we have correctly 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
1: Open Windows Command Prompt
Search for “CMD” in the “Start” menu and open the command prompt
Step 2: Enable
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 open 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
run the .sh file on 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.