Chat Zalo Chat Messenger Phone Number Đăng nhập
How to run .sh or Shell Script file in Windows 11/10

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

Shell scripts or . SH files are like Windows batch files that can run on Linux or Unix. It is possible to run .sh or Shell Script file on Windows 10 using the Windows Subsystem for Linux. In this post, we will show you how to run a Shell Script file on Windows 11/10.

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

Bash is a Unix shell and command language that can run Shell Script files. You don’t need to install Ubuntu or any other Linux distribution unless your scripts need actual Linux kernel support. We will share both methods.

Run shell script file using WSL Run shell script using

  1. Ubuntu on Windows 10 1] Run shell script file using
  2. WSL Install WSL

or Windows subsystem for Linux

Go to

Update and Security Settings > > for developers. Check the Developer Mode radio button. And find “Windows Features”, choose “Turn Windows Features on or off”.

Scroll to find WSL, select the check box, and then install it. Once done, one has to restart to finish installing the requested changes. Press Restart Now. BASH will be available at 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. .

  3. Type Bash script-filename.sh and press the Enter key
  4. .

  5. You will run the script, and depending on the file, you should see an output.

Run shell script files from command prompt

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

2] Run Shell Script using Ubuntu on Windows 11/10

Make sure you have Ubuntu or any other Linux distribution installed. Ubuntu will mount or make all your Windows directories available in /mnt. Therefore, drive C is available in /mnt/C. So, if the desktop will be available in /mnt/c/users/<username>/desktop.

Run script files on Windows via Ubuntu

Now follow these steps

Type

  1. Bash at the run prompt and the distribution message will start
  2. . Navigate to the folder using the “

  3. cd” command to the folder where the scripts are available
  4. .

  5. Type “sh script.sh” and press Enter.

It will run the script, and if they have a dependency on any of the core features of

Linux.

Since Linux is now available on Windows, you don’t need to use any third-party applications like Cygwin. WSL should be enough for most scenarios to help you run a shell script on Windows 11/10.

How do I create a . SH file?

The steps to create

a shell script file are: Create a file with

  • an editor
  • Script file name with .sh extension Start the script

  • with #! /bin/sh
  • Write the desired code
  • Save
  • the script

  • file
  • as ABC.sh

  • To run the script type bash ABC.sh.

Can shell scripts run on Windows?

Yes, now with Bash Shell in Windows

11 and Windows 10, you can now create and run Bash shell scripts and incorporate Bash commands into a Windows batch file or PowerShell script.

Contact US