Bash: Indirect Expansion Exploration

A common case that comes up when programming is accessing a variable that is received as a parameter. Bash scripting accomplishes this using something called indirect expansion, which will be our topic in this post. Setup Let’s make a shell script. In your favourite editor type #!/bin/bash x=2 letters=(a b c d) And save it…

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…

Bash Arrays 1: Intro, Declaration, Assignments, Dereferncing (accessing elements) and special subscripts

During my attempts at making a recursive shell script that ouputs a graphical tree display of a directory structure I ran into some trouble with arrays, so I decided to delve deeper into arrays to better understand them. Setup Let’s make a shell script. In your favourite editor type #!/bin/bash Save it somewhere as arrays.sh.…