MintGuide.org / How to create your own script (sh) on Linux Mint

How to create your own script (sh) on Linux Mint

First of all, let's understand what is script and what is it for.
We all watch movies, many of us - performances. To create a movie/show, the writers write the scripts to them on the basis of which actors, scene for scene perform on stage their roles. Work on creating a script rather laborious, where it is necessary to consider all the details that in the end, the artists were able to perform the intended writer, and the viewer saw a complete work.

Similarly, to write scripts to perform tasks the user is together (code) to make their implementation easier and faster in the operating system. For writing simple scripts does not necessarily have education as a programmer.

First, let's create the most that neither is a simple script-Shell to update the system.

So, open a text editor and enter in it the first must-have characters called shebang.

#!/bin/sh

Next, the following line should be a description of what needs to run our first script:

#My first Script for update Linux Mint

The sign (#) at the beginning of the line makes it clear to the interpreter/terminal that the string do NOT need read and do NOT need execute. Line is necessary in the code of this script to the Creator of the script knew what he was going to perform on this stage in code, to avoid confusion in future when these lines will be a lot. Such lines with the pound sign is called is commented.

Next, the script followed by running the line command, in this case to update the system:

sudo apt update
sudo apt upgrade -y

-y at the end of the second command makes it clear to the interpreter/terminal that this action/command needs to be run automatically, without additional confirmation by the user pressing the Enter key.
y - short for yes

How to create your own script (sh) on Linux Mint

Save the file/script and give it a Name with a required extension at the end .sh. Extension .sh is assigned to the executable file.
I gave it a Name - update.sh preserving the Home folder of the user.

To create a file/script was executable, you must give him permission to do so. This can be done in two ways.

Run the following command in the terminal:

sudo chmod +x update.sh

Or right click on file => Properties => Right and activate the item - Execute: Allow executing file as a program:

How to create your own script (sh) on Linux Mint

run the sh script:

sh update.sh

or

./update.sh

You can find the Internet useful scripts and use them in the system.

To use it easier to use some scripts, you can assign keyboard shortcuts to launch them or you can use hot corners. 

For example I added in Nemo this script

How to create your own script (sh) on Linux Mint

How to create your own script (sh) on Linux Mint

How to create your own script (sh) on Linux Mint

If you add the script to the shell of your file Manager will probably need a restart.

May the Force be with you,
Good Luck!!!

20-01-2017, 17:59
Go Back