What is a Script?
In the command line, we enter the commands we want to execute via the keyboard. In addition to this, it is also possible to automate this task by creating a script. A script is a file containing a set of commands that are executed sequentially, from the first to the last.
How to create a Shell Script
There are several ways to create a script; when it ends with a .sh extension, the system already identifies it, but does not give it execution permissions. An example of creating a script would be:
touch script.sh && chmod +x script.sh
where touch script.sh creates the script and chmod +x script.sh gives execution permissions
How to run or test a .sh script
We need to go to the directory where we have the script from the terminal. You might not have execution permission, so as mentioned in How to create a Shell Script, we must give it execution permissions with the following command: chmod +x script.sh.
To execute script.sh we will type:
./script.sh