▷ How to run SH files on Windows

Contents

The shell script files are written in the bash scripting language for Linux. Contains commands that can normally be run on the command line. These files can be called in Terminal to be executed and can be opened by double clicking. Nevertheless, Windows doesn't know what an SH file is and how to run it. If you are looking for a way to run SH file on Windows, this article will provide you with all possible methods.

sh-on-windows-4536356 Run SH files on Windows

What are SH files?

SH files (also known as script files) are the scripts that the Bash application programs and uses. The Bash language is used to write the instructions in these files. These files are used primarily by program developers. Since they contain the commands to run programs, they are really important. Nevertheless, these files are for Linux, so running them on Windows will require some software or environment that we will provide in the methods of this article.

For more information on SH files, you can check our article here. Moving on to SH file execution methods in Windows.

Method 1: using Cygwin to run SH files

Cygwin is an open source Unix-like command-line interface environment. Allows Unix or Linux applications to be compiled and run on a Windows operating system from a Linux-like interface. Con Cygwin, we can easily run SH files without any problem.

  1. Go to the official Cygwin site to download the configuration file from 32 bits o 64 bits: Cygwin cygwin-9657759 Cygwin download page

  2. Open the downloaded installation file and follow the Cygwin download and installation process. There are different options in the installation process, so choose the ones you prefer.

  3. After installation, open the Cygwin64 terminal by double clicking the shortcut on the desktop.

  4. Now use the following command to change the directory where the file exists:

    cd C:Users/Username/Desktop

    This will change the directory to the desktop. Now type the following command to run SH File:

    sh appuals.sh

    cygwin2-4423368 Running the script file through Cygwin

Method 2: using the Windows subsystem for Linux function in Windows 10

The Windows Subsystem for Linux (also known as WSL) is a feature that allows users to run Linux command lines on a computer with a Windows operating system 10 installed. This feature was first added to Windows 10 on 2016. Just as Linux has Wine software to run Windows software, Windows now has WSL to run Linux software. Nevertheless, enabling and working with this feature will require many steps, so we have divided this method into three big steps and they are listed below:

Paso 1: enable the subsystem from Windows to Linux

  1. Hold down Windows and press R to open Run, then type appwiz.cpl and Enter. appwiz-15-9839022 Open programs and functions

  2. Click the Turn Windows Features On or Off option on the left side. appwiz2-1-1263007 Open Turn Windows features on or off

  3. Scroll down and check the Windows Subsystem for Linux and click OK to install. windows-features-4950871 Enabling the Windows Subsystem for Linux

  4. Once this is done, continue to next step.

Paso 2: install a Linux distribution for Windows

There are three different ways to install a Windows distribution. Nevertheless, sometimes one of the methods won't work for a specific user, so we will provide the three methods below:

  1. Hold down the Windows key and press R to open Run, scribe $ 0027 ms-windows-store: $ 0027 without the quotes and Enter. windows-store-2376893 Open the Windows Store

  2. International throwers. Click on the one below and download it: ubuntu-8592114 Download Ubuntu from the Windows Store

  3. The second method is to use the following Power Shell command to download the Linux distribution:

    Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing

    powershell-3027366 Download distribution via Power Shell

  4. The third method to download the distribution is by using the following curl command:

    curl.exe -L -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604

    curl-8660353 Downloading the distribution via the curl command

    Note: If your Windows build number 10 is less than 1706, then you need to download curl manually and change directory to the location where curl.exe is located. Nevertheless, if your windows build number 10 it is 1706 the later, then curl is included by default and you have to run cmd as administrator.

  5. Once you download a distribution, it will start the installation automatically and you just need to accept and provide the new username and password as shown below: package-vert-1-8527733 Ubuntu installation and configuration

Paso 3: initialize a newly installed distribution and run the SH file

  1. Most of the distributions you will install come with the empty package catalog / minimum. Then you need to update and update the packages using the following command:

    sudo apt update && sudo apt upgrade

    windows-feature3-4919221 Update and update packages

  2. Once you are done with the distribution, now you can change directory to SH file location using following commands:

    cd /mnt

    This will mount your Windows drives. Now you can go to the location you want:

    cd c/Users/Username/Desktop/

    Note: Since the sample file was on a desktop, we change the directory to desktop.

  3. Enter the following command to run the SH file:

    sh appuals.sh

    windows-feature4-6623172 Change directory and run SH file

Method 3: use Git command line to run SH files

Git is a distributed version control tool, free and open source available for all operating systems. By default, Git installs on Linux and MacOS computers as a command line option. Nevertheless, you can also download it from the official site for all operating systems.

  1. Go to the following link to download Git for your operating system: Git

    git1-9021765 Download Git for Windows

  2. Open the downloaded setup file to install Git. Go through the installation process and check the options you want and those you don't.

  3. Hold down the Windows key and press S to open the search function, type Git Bash and Enter. git2-2859010 Abhir Git Bash

  4. Change the directory where your file is located with the following command:

    cd desktop

    Note: Desktop can be the name of the folder where your file is located.

  5. Now type the command SH run:

    sh appuals.sh

    git3-4391667 Running the SH file in Git Bash

Method 4: translate script file to batch file

This method is not recommended for average users, but rather for users who know bat and script file commands very well. You can change the format and extension of the SH file. Requires the ability to translate the script file to a batch file, so you should avoid using this method unless you know what format both files use. We will show you the simple steps required to make changes to the sample code.

  1. Right-click on your SH file and choose Open With> Notepad.

    batch1-4409722 Open SH file in notepad

  2. Remove the shebang line from the code as shown below: batch2-8938399 Delete the shebang line

    Note: Comments will have a syntax »::»Different from this sample.

  3. Click on the file and choose Save from the list to save your changes. batch3-3494087 Save Changes

  4. Left click on the SH file and press F2 to rename the file. You can also right click on a file and choose to rename. batch4-9250983 Change the file extension

    Change the extension from .sh to .bat and click Yes to see the changes.

  5. Hold down the Windows key and press S to open the search function, then type cmd and Enter.

  6. Change the directory to the path where the file is located using the cd command:

    cd desktop

    Note: The desktop may be the name of the folder you are trying to access.

  7. Now just type the file name with the extension:

    appuals.bat

    batch5-8183148 Open batch file in cmd

    Nevertheless, you will notice that the syntax that works in script files does not work in a batch file. As you can see, the comment is ignored and the text will print twice without echo $ 0027on / off $ 0027.

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.