This post is part of an educational series on building a shell script to graphically display the structure of a directory. While you are surfing your linux in command line, sometimes you want to be able to see the directory structure spread out in your terminal. I personally don’t know of any native command that…
Recursion in programming is when a piece of code (usually a function) calls itself. If there is no exit case, the program will go on forever. We will be discussing recursion in a bash script with examples and discussing some peculiarities of the bash shell, such as local variables. Setup Let’s make a shell script.…
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.…
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…
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…