run sh files windows and linux

A .SH file is a simple text file that contains the commands and a little logic to it. There are several ways to run a .SH file. A .SH file is very similar to the batch file of the Windows operating system and can be run in the Linux-based operating system. It is also possible to run .SH file in Windows 10 using Windows Subsystem for Linux.

In this tutorial, we will show you how to run .SH files in Linux and Windows 10 systems.

Run .SH Files in Linux

In this section, we will show you how to run .SH file in Linux with examples.

Basic Steps to Run .SH Files

Before running .SH files, you will need to give execute permission on your file that you want to run. You can set execute permission with the following command:

chmod +x yourfilename.sh

Or

chmod 755 yourfilename.sh

Next, you can run your .SH file by running the following command:

sh yourfilename.sh

Or

bash yourfilename.sh

Or

./yourfilename.sh

Run .SH file as a root User

In some cases, you will need root access to install application or make system level modifications with .SH file. You can run .SH file as a root user by using the sudo command as shown below:

sudo bash yourfilename.sh

Type your user password and hit Enter to execute the .SH file.

You can also use su command to login with superuser and execute the .SH file.

First, switch the user to root with the following command:

su -

Next, run .SH file with the following command:

bash yourfilename.sh

Run .SH file with CHMOD Command

You can also use chmod command to run .SH file. First, set the execute permission on your file with the following command:

chmod +x yourfilename.sh

Next, run .SH file with the following command:

./yourfilename.sh

If your file is located at /opt directory then run the following command:

./opt/yourfilename.sh

Run .SH file with GUI Method

You can also run .SH file with Graphical user interface. To do so, first right click on the file that you want to run as shown below:

Next, click on the Properties. You should see the following screen:

Next, click on the permisssion tab and select Allow executing file as a program as shown below.

Next, double click on the file to execute the file.

Run .SH files in Windows 10

There are several ways to run .SH files in Windows 10 operating systems.

Run .SH file with WSL

WSL stands for “Windows Subsystem for Linux” is a compatibility layer for running Linux binary executables natively on Windows 10 and Windows Server 2019. It allows you to run native Linux command-line tools directly on Windows.

First, you will need to install WSL in your Windows 10 systems.

To do so, go to Settings > Update & Security > For Developers and check the Developer Mode radio button. Then, search for “Windows Features”, choose “Turn Windows features on or off”.

Next, scroll down, find WSL, check the box and install it. After installing WSL, you will need to restart your system to finish the installation.

Next, open the Command prompt, change the directory where yourfilename.sh is located and type bash yourfilename.sh to execute your file as shown below:

Run .SH File with Ubuntu on Windows 10

If you want to run .SH file in a Linux environment on Windows 10 then you will need to install Ubuntu or any other Linux distros on Windows 10.

You can install Ubuntu on Windows 10 by following the below steps.

First, go to Settings > Update & Security > For Developers and check the Developer Mode radio button. Then, search for “Windows Features”, choose “Turn Windows features on or off”.

Next, scroll down, find “Windows Subsystem for Linux (Beta)”, check the box and click Ok to install it. Once the installation has been finished, you will need to restart your system to finish installing the requested changes.

Next, open your Command prompt, type bash and hit Enter to install Ubuntu on Windows 10. Once the installation has been finished you should see the following screen:

Now, change the directory with cd command to the directory where yourfilename.sh is located and hit Enter to run the file as shown below:

Conclusion

In the above tutorial, we learned how to run .SH files in Linux and Windows 10 operating systems. I hope you have now enough knowledge to run .SH files in Linux and Windows 10.

Leave a Reply

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