Files with the.shextension, i.e., shell scripts, are designed to be run by Unix shells such as Bourne or GNU Bash. If you attempt to run shell scripts in Windows, it won’t work as the commands won’t be recognized by default.

Instead, you’ll have to introduce a compatibility layer to be able to run such scripts in Windows. There are various ways to do this, with the popular ones being Windows Subsystem for Linux, Cygwin, and Git Bash.

In this article, we’ve listed all the necessary steps to run Shell Scripts in Windows using these methods.

windows-subsystem-for-linux-virtual-machine-platform

Windows Subsystem For Linux

The first method is toinstall a Linux distrothrough the Windows Subsystem for Linux feature. Cygwin and Git are convenient, but users often have difficulty running complex shell scripts and Linux applications with them. As such, WSL is the recommended option. Here are the necessary steps for this:

Cygwin is a run time environment used to run code designed for Unix environments on Windows. Here’s how you may run shell scripts in Windows using Cygwin:

During its installation, Git optionally adds some UNIX tools to the PATH in Windows, withsh.exebeing one of them. Here’s how you may install Git and run shell scripts using Git bash:

gigabyte-svm

get-debian-microsoft-store

wsl-debian-installation

wsl-debian-sudo-apt-update

wsl-shell-script-in-windows

cygwin-installation-confirm-changes

cygwin-shell-script-in-windows