1. Home
  2. Windows Tips
  3. Run shell script on windows 10

How to run a Shell script on Windows 10

Every desktop operating system allows its users to run scripts. On Windows 10, you can run a batch script, a PowerShell script, an AHK script, a VBS script, and more. One script type you can’t run out of the box is a Shell script. A Shell script is written and used on Linux systems. They’re awesome, and many Linux users are of the opinion that they are better than anything Windows has to offer in terms of scripting.

If you have a shell script that you’d like to run on Windows 10, there are a few ways to do it however, there will be limitations. We have two different methods that you can use to run a Shell script on Windows 10. Pick the one that suits you best.

Limitations

Before we proceed, it is important that you understand the limitations you have to work with. A Shell script is written for Linux. If it finds a Linux environment, it should be able to run, but the environment itself must have all the components the script needs to be able to run. This means that some scripts may work, while others may not because a component they need is missing.

One other thing you should know is that on Linux, the forward slash is used to denote a directory. This will help when you need to use the cd command.

To help you figure out whether or not you’ve been successful in running a Shell script on Windows 10, we recommend using the test script below.

Test shell script

Open Notepad and paste the following. Save it with the SH file extension.

#!/bin/bash
echo "Stay Home"

This is a very simple script that will display the message ‘Stay Home.’ It will be able to run since all it has to do is display text within the shell that it’s running in.

Run Shell script on Windows

Run Shell script on Windows 10 with WSL

Windows 10 supports Linux. What this means is that you can install a Linux distro such as Ubuntu on Windows 10 and run Linux commands on it. To enable WSL on Windows 10, follow these steps;

  1. Open Control Panel.
  2. Go to Programs
  3. Click Turn Windows features on or off.
  4. In the window that opens, scroll to the end, and enable Windows Subsystem for Linux.
  5. Install it, and restart your system when/if prompted to.
  6. Once you’re back on your desktop, install Ubuntu from the Microsoft store.
  7. Restart your system when/if prompted.
  8. Once you’re back on your desktop, open Windows search, type Ubuntu, run the app, and set it up.
  9. You’re now ready to execute the script.

Run shell script in WSL

Find the path to the script you want to run;

  1. Navigate to the script in File Explorer.
  2. Hold down the Shift key and right-click the script.
  3. Select the Copy as a Path option.
  4. Paste the path in a Notepad file and replace the backslash with a forward slash throughout the path.
  5. Open Ubuntu.
  6. Run the following command to go to the directory that the script is in.

Command

cd path-to-script

Example

cd /mnt/c/Users/fatiw/Desktop/
  1. Run this command to run the script.
sh name-of-script.sh

Run Shell script on Windows 10 with Git Bash

Using WSL to run a Shell script in Windows 10 is a long process. If you want something much quicker, we recommend using Git Bash. Go ahead and download Git Bash. Install it but, during installation, make sure you allow it to be added to your PATH variable.

Once the installation is complete, open Git Bash. Drag & drop the shell script onto the window, tap Enter, and it will be executed.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.