How to run .sh or Shell Script file in Windows 10

Run Shell script files from Command Prompt

Shell Scripts or .SH files are like Windows batch files that can be run on Linux or Unix. It is possible to run a .sh or shell script file in Windows 10 using the Windows subsystem for Linux. In this article, we will show you how to run a shell script file in Windows 10.

How to run a .sh or shell script file in Windows 10

Hit is a Unix shell and command language that can execute shell script files. You do not need to install Ubuntu or any other Linux Distros unless your scripts require support for the actual Linux kernel. We will share both methods.

  1. Run a shell script file with WSL help
  2. Run a shell script with Ubuntu on Windows 10

1) Run a shell script file using WSL

Install the WSL or Windows Subsystem for Linux

Go to Settings> Update & Security> For Developers. Check the Developer mode radio button. And search "Windows Features", Choose"Enable or disable Windows features".

Scroll to find WSL, check the box and install it. Once done, you must restart to complete the installation of the requested changes. Tap Restart Now. BASH will be available in the Command Prompt and PowerShell.

Run shell script files

  1. Open the command prompt and navigate to the folder where the script file is available.
  2. Type Bash script-filename.sh and press the Enter key.
  3. It will execute the script and, depending on the file, you should see an output.

On a Linux platform, you usually use SH, but here you must use BASH. That said, BASH in Windows has its limits, so if you want to run in a Linux environment, you have to install Ubuntu or something similar.

2) Run a shell script with Ubuntu under Windows 10

Make sure you have Ubuntu or any other Linux distribution installed. Ubuntu will mount or make all your Windows directories available under / mnt. So, the C drive is available at / mnt / C. So, if the office will be available to / mnt / c / users // office.

Run script files on Windows via Ubuntu

Now, follow these steps

  1. Type Bash in the prompt, and it will launch the distribution prompt.
  2. Navigate to the folder with the help of the "cd" command until the folder in which the scripts are available.
  3. Type "sh script.sh" and press Enter.

It will execute the script and if they depend on one of the main features of Linux.

Since Linux is now available in Windows, you do not need to use third-party applications such as Cygwin. WSL should suffice in most scenarios to help you run a shell script in Windows 10.


Leave a Reply

Your email address will not be published. Required fields are marked *