What is shell script? This may be a fairly common question for those who are starting out on the Linux system.
Linux offers several solutions for the Information Technology area, making life much easier for system administrators.
However, not all IT professionals are aware of all its advantages and the tools that can be incorporated into it.
Among them is the Shell Script, which is very useful in the process of automating tasks. And in this article we are going to explain what it is and practical application examples.
We give the name of shell script to files that will be interpreted by Shell-type programs.
With it, it is possible to create various commands for Linux. In other words, create tasks that will be done from time to time, automating this process, in addition to startup scripts and other functionalities.
Whenever an actor goes to make a scene, whether in the cinema, television or theater, he is given a script. A text that contains various information about how it should act during the scene, what are the important points for the narrative to unfold.
Scripting on the computer works in a very similar way. They are a series of instructions that dictate how the device must perform tasks x, always according to the program.
Lines of code, within the programming language, can use a script to, for example, count the number of daily accesses, whether done via desktop or mobile, geolocation, and much more.
Scripts can, of course, go much further than that. With them, it is possible to change the page’s look, colors, layout and even, as mentioned above, add useful functions to the page.
In general, we can say that Shell is a layer that allows users to access and configure commands in the operating system.
To better understand, imagine a turtle. It has a carapace that surrounds and protects it from the outside world. So her body itself has no major damage.
In a practical way, the Shell works as a kind of intermediate interface between the user and the operating system. It has selective functions and only allows the execution of actions according to the access level of each user.
However, basically, there are two types of Shell: the CLI and the GUI.
Acronym for “Command Line Interface”, that is, those that have an interface based on a command line. In other words, for any action to be performed, an equivalent command must be typed.
Acronym for “Graphical User Interface”. In this case, the graphical interface is used so that the same commands do not have to be typed more than once.
In short, whether through a graphical interface or with command lines, the Shell performs basic operating system actions in order to better manage computer data.
This can happen with files that are stored on devices or even when running other applications.
Now that we know what shell scripting is, let’s dive deeper into its language!
Like other programming languages, the shell script language has variables in its structure, in addition to decisions and repetition ties. Check out some of them!
In a basic way, almost all variables in the Shell Script language are of the string type. It is, of course, possible to convert the type of variable depending on the type of operation you want to perform.
There is the possibility to create arrays, perform arithmetic operations, among other functions.
However, in the case of variables that are actually of the string type, it is recommended to use quotes so that there is no risk of the interpreter trying to execute the string as a form of command.
Mathematical calculations can be performed in Shell Script using several arithmetic operators:
However, doing the operations is not such a simple task. The variables follow the string pattern, which requires some maneuvering to execute the operations.
See below how to perform arithmetic operations.
When we talk about comparison operators, Shell Script has characteristics that are little different from other programming languages. See below:
Every programming language makes use of decision structures to control system flow through logical decisions.
These decisions are written using logical expressions that make use of comparison operators to assess whether or not that expression is true.
The shell script can implement several very useful applications to the system. We’ve listed some of them below!
With the shell script it is possible to automate routine tasks on your machine, such as system updates, upgrades, cleaning, etc.
It is also possible to create, edit, locate, and organize files using a shell script.
The shell script can also be used to configure directories for automatic backups and insert utility arguments into them.
That way, dead files can be moved or copied to another location.
Is it clear what shell scripting is? It is an excellent tool that “makes” the user and administrator’s life easier. After all, automating tasks streamlines deliveries and increases process reliability.
The sudo command on Linux executes a given command as if it were another user.…
The ss command on Linux is extremely useful for investigating sockets, providing various information about…
Free Linux command shows the amount of total memory in use and available, as well…
The shell has structures for testing conditions and executing certain program sequences several times (loop),…
The /etc/fstab file stores the configuration of which devices should be mounted and what is…
The Netcat Command in Linux or nc is a utility used to do “almost anything”…
This website uses cookies.