How to run .sh files

how to execute sh file
Discover how to run it with the terminal and double clicking

The files with extension .sh are files that contain scripts, commands in bash language, which runs on Linux. SH is a Linux shell that tells the computer what to do.

In a way we could say that it would be comparable to the Windows .exe.

There are different ways to run it. I'm going to explain 2. One with the terminal and another with the graphical interface, that is, with the mouse, that when you double-click it is executed. You can see it in the video and below is the step by step for those who prefer traditional tutorials.

Run .sh with graphical interface and mouse clicks

If you prefer to do everything at the click of a mouse, you can also do it. To make it work like in Windows, double click on the file and it starts. There are 2 steps that are very quick to configure.

The first thing is to choose to tell it that the file is executable

Go to where the file is and click on it with the right button. A menu will be displayed and we give properties

Subscribe to our mailing list

right click on the .sh file

You select the check of Allow file to run. in this way we give execution permissions

give execution permissions to the file

We can take advantage to modify the tab To open with, which is the program that we choose as default for Aprilos, in case instead of executing them we want to open them and see what they contain. I use Gedit or Visual Studio Code

Then we have to configure the file manager

Finally in the file manager go to the menu and choose preferences and the tab Behavior and there you can tell it what you want to do with the file.

file manager preferences

There are several options. Open the file, run it or ask us. I have chosen to ask us. And so it will be shown to us.

run sh with double click

Run .sh with terminal

We open terminal, with Ctrl + Alt + T, start key and write terminal or with the shell icon that I always have in the Ubuntu launcher, come on, in the left sidebar.

The way to run it is to go to the directory where the file is located. imagine we have an ok.sh file in the / scripts / folder

We enter scripts with (you have to go to the path where you have it)

cd scripts

If this is the first time we run it, we must give the file permissions

sudo chmod + x ok.sh

And then we run it

./ok.sh

And voila here is the sequence

run sh in terminal

In our case, "Ok" comes out because we have entered what that script does.

The most important thing and what people make the most mistakes is in the path, in the path, in not accessing the folder where the file to be executed is.

If you have any questions, leave a comment.

Extra if you want to learn

Some little things if you want to learn. There are more commands to run a .sh you can do

./file.sh the. indicates that the file is in the current directory, if you can't run it with the path to the file path / to / file.sh

Another command to run in addition to ./sh file is

sh file sh

Leave a comment