How To Execute Shell Script In Windows
Bash shell script files are written in bash scripting language for Linux. Information technology contains commands that y'all tin can normally run on the control line. These files can be called in Terminal to execute and can exist opened by double-clicking. However, Windows does not know what an SH file is and how to execute it. If you are looking for a way to execute SH file in Windows and then this article will provide yous with all possible methods.
What are the SH Files?
SH files (also known as script files) are the scripts that the Fustigate application programs and use. Bash linguistic communication is used to write the instructions in these files. Program developers by and large utilize these files. Since they contain the commands to execute programs, they are indeed important. Even so, these files are for Linux, so executing them on Windows will require some software or environment that we will provide in methods of this article.
For further data well-nigh SH files, you can check our commodity hither. Moving on towards methods for executing SH files on Windows.
Method 1: Using Cygwin to Execute SH Files
Cygwin is an open source command line interface environment similar to Unix. It allows Unix or Linux applications to be compiled and run on a Windows operating organization from within a Linux-like interface. Past using Cygwin, we can easily execute SH files without any problems.
- Go to the Official Cygwin site to download the 32bit or 64bit setup file: Cygwin
Download site for Cygwin - Open the downloaded setup file and follow the process of downloading and installing Cygwin. In that location are different options in the installation process and then choose the ones you prefer.
- After installation, open Cygwin64 Terminal by double-clicking the shortcut on the desktop.
- Now utilise the post-obit command to change directory to where the file exists:
cd C:Users/Username/Desktop
This volition change the directory to the desktop. Now type the post-obit command to execute SH File:
sh appuals.sh
Executing script file through Cygwin
Method 2: Using the Windows Subsystem for Linux Feature in Windows 10
The Windows Subsystem for Linux (aka WSL) is a characteristic that allows users to run Linux command lines on a computer with a Windows 10 operating arrangement installed. This feature was first added to Windows 10 in 2016. Just similar Linux has Vino software for running Windows software, now Windows has WSL for running Linux software. However, enabling and working through this feature will require many steps, which is why nosotros divided this method into iii major steps and they are listed equally follow:
Step ane: Enabling the Windows Subsystem for Linux
- Hold Windows Fundamental and Press R to open up Run, then type appwiz.cpl and Enter.
Opening Programs and Features - Click on the Turn Windows Features on or off on the left side.
Opening Turn Windows features on or off option - Coil down to the lesser and tick Windows Subsystem for Linux and click Ok to install.
Enabling Windows Subsystem for Linux - In one case this is done, move to the next pace.
Step 2: Installing a Linux Distro for the Windows
At that place are three dissimilar means to install a distro for Windows. However, sometimes ane of the methods will not work for a specific user, so we are going to provide all 3 methods below:
- Concord Windows primal and printing R to open up Run, type 'ms-windows-store:' without the quotation marks and Enter.
Opening the Windows Shop - Search for Ubuntu. Click on the one that is shown beneath and download it:
Downloading Ubuntu from Windows Store - The second method is to utilise the following Power shell command to download Linux distro:
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing
Downloading distro through Power Shell - The third method to download the distro is using the following curl control:
gyre.exe -L -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604
Downloading distro through curlicue command Note: If your Windows 10 build number is less than 1706 then you need to download curl manually and change directory to that location where curlicue.exe is located. Notwithstanding, if your windows x build number is 1706 or after then curl is included by default and you need to run cmd as an administrator.
- One time yous download a distro, it will get-go the installation automatically and you demand to just agree and provide the new username and countersign as shown beneath:
Installing and setting up ubuntu
Step 3: Initializing a Newly Installed Distro and Executing SH File
- Most distros that you will install comes with empty/minimal package catalog. So you lot need to update and upgrade the packages by using the following command:
sudo apt update && sudo apt upgrade
Updating and Upgrading packages - Once you are done with the distro, now you lot can modify directory to the SH file location past using the following commands:
cd /mnt
This will mount your Windows drives. At present you tin can get to the location you want to:
cd c/Users/Username/Desktop/
Notation: Since the sample file was on a desktop so we changed the directory to desktop.
- Type the following command to execute the SH file:
sh appuals.sh
Changing directory and executing the SH file
Method three: Using Git Command Line for Executing SH Files
Git is a free and open source distributed version control system tool available for all operating systems. By default, Git is installed on Linux and macOS computers every bit a command line selection. However, you can also download it from the official site for all operating systems.
- Become to the post-obit link to download Git for your Operating Organization: Git
Downloading Git for Windows - Open the downloaded setup file to install Git. Go through the installation process and do check the options which y'all desire and which you don't.
- Hold Windows cardinal and Printing S to open search office, type Git Bash and Enter.
Opening Git Bash - Change directory to where your file is located by the following command:
cd desktop
Note: Desktop can be the name of the folder where your file is located.
- At present blazon the SH executing command:
sh appuals.sh
Executing SH file in Git Bash
Method 4: Interpret Script File into Batch File
This method is non recommended for average users, merely for the users who know script and bat files commands very well. You can just change the format and extension of SH file. It does require the skill of translating the script file into a batch file, so you should avert using this method unless you know what format both these files utilize. Nosotros are going to show you the unproblematic steps required for the sample code changes.
- Right-click on your SH file and choose Open with > Notepad .
Opening SH file in Notepad - Remove the shebang line from the lawmaking as shown below:
Removing the shebang line Annotation: The comments volition accept a dissimilar syntax "::" than the 1 in this sample.
- Click on the File and cull Salvage in the list to salvage the changes.
Saving the changes - Left-click on the SH file and press F2 key to rename the file. You can besides right-click on a file and choose rename.
Changing the extension of the file Change the extension from .sh to .bat and click Yeah for the changes.
- Hold Windows primal and Printing S to open search function, and so type cmd and Enter.
- Change the directory to the path where the file is located by using the cd command:
cd desktop
Annotation: Desktop can be the folder name that yous are trying to access.
- Now simply type the name of the file with extension:
appuals.bat
Opening batch file in cmd Withal, yous volition notice that the syntax that works in script files are non working in a batch file. As you lot can see, the comment is being ignored and the text will be printed twice without echo 'on/off'.
Source: https://appuals.com/how-to-execute-sh-files-on-windows/
Posted by: brownwitheme.blogspot.com

0 Response to "How To Execute Shell Script In Windows"
Post a Comment