In computing, we know as “scripts” to textual command lines with which you can execute predetermined actions in a wide variety of programs on the computer.
Scripts can performed on almost any operating system and they fulfill fundamental functions in the structural base of all the programs with which we work every day.
Linux is one of the most used operating systems for scripting, thanks to the large number of tools it offers. We will now teach you how to use this practical operating system for creating your own commands or scripts.
What is a Script and what are these programs for in Computer Science?
A script, in the context of computing, is commands in the form of lines of text that contain commands in uncompiled code. It is written in any programming language, and designed to be read by an intelligent terminal and translated into machine language.
They are tools widely used in the development of software and web pages, as they facilitate the customization of these, offering the possibility of improving their appearance and functionality. Scripts are used to automate repetitive tasks and interact with the computer’s operating system, as well as performing autonomous software installations and creating forms, among other functionalities.
Types of Script Which ones exist and how do they differ from each other?
For the most frequently required functionalities, there are three types of scripts. The three types of lines share functions that seek to execute functions on the computer.
Go for it:
Route scripts
They are used for the automation of processes, since they are saved with a specific command path. It can be programmed to automatically start an action or start after the user executes a particular route.
Standalone scripts
Unlike the first ones, it is not assigned to any specific type of path, but rather they are saved as external files. They can be used to manage multiple routes and share the same syntax checking options with route scripts.
Supernode scripts
Supernode scripts are only available in terminal supernodes and are used to program the order of execution of various streams and scripts. In addition to this, they can interact with other supernode commands to define their properties.
What are the main programming languages used to write Script correctly?
There is a great variety of programming languages which are more than adequate sources for writing scripts.
Although the most used is JavaScript, we present other languages that you can use:
- JavaScript: it is the most widely used language for scripting. It is a variant of the ECMAScript language and is also the most used in web browsers such as Chrome or Firefox.
- Python: after JavaScript, it is the most popular and widely used programming language thanks to the simplicity of its syntax. It is object-oriented and supports structured programming patterns.
- PHP: Created for writing scripts that were used to add functions to static HTML sites, it has evolved as a language in its own right and is used for hypertext processing.
- Ruby: it is an almost exclusively object-oriented scripting language. Its code is open and has a consistent and understandable syntax. Besides that, it also supports functional and procedural programming.
- Groovy: it has JavaScript compatibility, it is very flexible and functional. It is object oriented and has a large variety of automation building tools.
- GML: is the acronym for GameMaker Language and is widely used in writing game development scripts. It is a procedural-oriented language and its use is governed by its owner GameMaker Studio 2.
- Lua: lua works by compiling the source code before running it through your virtual machine. This step is done automatically, so manual compilation is unnecessary. It is fast, light and its syntax is similar to that of Python.
- Bash: It has a simple and descriptive syntax and can be used to automate administrative tasks, connect to remote servers, execute commands, and other processes related to the operating system.
- PowerShell: it can be used on Windows, Linux and macOS operating systems for configuration management and system administration. It has a very compact syntax, which greatly facilitates command line work.
- Perl: is a very old general-purpose programming language created over thirty years ago. It has a similar syntax in C language and is a solid option to use in the CGI execution environment.
Learn step by step how to create a Script on your computer with Linux operating system from scratch
Being a practically perfect operating system for development and programming, creating an executable script on Linux is a really simple process. To write a simple script, the language will be used Bash. All you are going to use will be a text editor, it can be the one of your preference. The first step is create a text file in the location where you want to have the script.
The first line of code should be #!/bin/bash
in order for the file to be recognized as a script. the lines that start with echo
will contain the texts that will appear on the console, with sleep
will determine the waiting time, then the path of our user is created on the line cd
, and the last three lines update the repositories and software, as well as install another small series of applications.
When finished, the text of the script will look similar to the following, after which you must save the file with the name of your preference, but always with the extension “.sh”: