Using programming structures
In this section, we will show you how to use conditional and looping statements. They can prove invaluable when creating advanced shell scripts. We will also show you how to use arrays, how input reading is used inside scripts, and how to format and print data for the output.
Using arrays in Bash
We showed you how to use variables in previous sections. Now, it is time to step up our game and show you how to make use of arrays, a more complex form of variable. Let’s say that we need to work with multiple variables that may store similar information, such as filenames. Instead of using multiple variables in the form of filename1
, filename2
, filename3
… filenameN
, we can create an array that will hold all the filenames. If you know other programming languages, arrays may already be familiar to you. But if you don’t know any other programming languages, fear not, as Bash has a facile way of using arrays.
Let’s start with...