Basics of shell scripting
We have already covered important aspects of the Linux command line, shell variables, wildcards, and metacharacters. Now, we will start exploring what scripts are, how to create them, and how to use them in a Linux CLI. We will not use the graphical user interface, only the CLI, which we primarily used in our previous chapters. Let’s start with some basic, but important, concepts about shell scripting.
First, let’s learn what a script is. If we were to check the meaning of the term in a dictionary, the answer would be that a script is a series of instructions that are executed by a computer, mainly to automate a specific task. Instructions can easily be assimilated as commands too. Thus, a series of commands executed together by the shell can be considered a script. This is a very basic script, but it is a script. Let’s look at how we can create a script file.
Creating a shell script file
The most appropriate way to write scripts...