Bash Arrays: Exploring and Experimenting with Bash Arrays

This is a series of posts exploring bash arrays, from the basics to more advanced usages. I began the series in an attempt to understand bash arrays as I was building the Shell Tree script How to declare an array and set its elements How to get the indices of an array How to cycle…

Bash Arrays 5: Local Arrays in Recursive Functions

When making a bash recursive function we have to pay special attention to local variables. One special case is when we wish to pass an array to a recursive function. When making recursive function, we have to be careful how we use variables. This post will deal with passing arrays as parameters to recursive functions.…

Bash Arrays 4: Passing Arrays as Function Arguments/Parameters

We will discuss passing arrays as arguments to functions. Pre-requistites Knowing how to declare an array and set its elements Knowing how to get the indices of an array Knowing how to cycle through an array Knowing how to copy an array Understanding indirect expansion Setup This is the same setup as the previous post…

Bash Arrays 3: Different Methods for Copying an Array

Pre-requistites Knowing how to declare an array and set its elements Knowing how to get the indices of an array Knowing how to cycle through an array Setup This is the same setup as the previous post Let’s make a shell script. In your favourite editor type #!/bin/bash And save it somewhere as arrays.sh. Now…

Bash Arrays 2: Different Methods for Looping Through an Array

In the previous shell array post we discussed the declaration and dereferencing of arrays in shell scripts. This time we will take a look at the different ways of looping through an array. Setup This is the same setup as the previous post Let’s make a shell script. In your favourite editor type #!/bin/bash And…