Shell scripts are like batch files for Windows. You can run .sh or shell script files in Windows 11/10 using the Windows Subsystem for Linux. This article will tell you three different ways to run shell script files on Windows.
Windows Subsystem for Linux
Use the Windows Subsystem for Linux or WSL for running Linux binary executables natively on Windows systems. It allows you to run shell scripts in Windows 11/10.
Enable WSL through the Windows device’s developer settings. Open Settings, tap Update & Security, tap For developers. Switch to developer mode and select Yes. Find Windows features and select the Turn Windows features on or off option. You will see the “Windows Subsystem for Linux” feature listed in a popup. Check this option and click OK to install. After a minute or two, restart your computer.
After rebooting, head over to the Microsoft Store and download Ubuntu, it will give you the Linux distribution. Open Ubuntu, let it install on your hard drive and integrate with WSL. Then create a username and password. Distributions for Windows can also be installed using the Power shell command “Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing” or the curl command “curl.exe -L” -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604″. Next, update and upgrade your Linux distribution by downloading additional packages using the command ” sudo apt update && sudo apt upgrade “.
Then run the shell script in the Windows command prompt. Locate the script file stored as a text file on your system, then hold down the Shift key while right-clicking on an empty space within the folder where the script file is located. You’ll see the option to “Open a command prompt here” or “Open a PowerShell window here”. Select this option, type “bash” in a Command Prompt window or PowerShell interface, and press Enter to launch the release prompt. This indicates that the Windows environment has been changed to BASH. Finally, you can start typing the .sh file in a terminal window and press Enter.
Cygwin has a set of GNU and open source tools that can compile Unix or Linux applications or programs and run them on Microsoft Windows Operating System (OS) in a Linux-like interface similar to Linux BASH.
Download and start installing the setup-x86_64.exe file on Cygwin’s official website (64-bit version is recommended). Because 32-bit Cygwin is only suitable for limited scenarios, including when the 64-bit version of Cygwin cannot be run. After downloading the GUI installer (which can be run to download a full Cygwin installation), open it in the Downloads folder and follow the instructions on each screen to install Cygwin. Its website also has detailed documentation on setting it up.
Then open the Cygwin64 terminal. Provide the command ” cd C:Users/Username/Desktop ” to change directory to where the script files are stored. After that, you can start executing the shell script. Just type the SH filename and .sh extension (for example, sh test.sh).
Git is a free, open-source version control system that tracks changes you make to files over time, allowing you to see who made changes to files at different times and restore files to their previous state.
The Windows version is available for download on the official Git website, visit your downloads folder and open the downloaded installation file to start the Git installation. Follow the instructions displayed on the device screen, selecting the “Git bash Here” option in the pop-up list of the window that confirms the required component settings. The rest can be left as default options. Finally select the Install button. Close the installation wizard and open Git Bash by searching on your computer. You’ll see other Git-related applications, but click the one that says “Git Bash”.
After booting, you need to use the command “cd desktop” to change directory to where the file is located. Additionally, you can go to the folder where the SH file is stored and right-click on that folder to select the “Git Bash Here” option. When the Git command terminal or Git Bash appears, you can start putting SH to execute commands. Just type the SH filename and .sh extension (for example, sh test.sh).