Using custom functions in shell script code
Up to this point, all we did was create very simple scripts that had a few commands at most. This is going to be most of your scripts since a lot of work that is solved by scripting is the simple elimination of repetitive tasks. In this chapter, we are going to work with functions as a way of creating modules of code in your script. Their main purpose is going to be to avoid repetitive blocks of code in your scripts, further simplifying the scripts themselves.
Getting ready
When it comes to functions, Bash is a little bit strange. Things you may know about functions from other languages will look similar in bash
but at the same time, completely different. We are going to start with how a function is defined. To make matters confusing from the very start, bash
uses two very similar notations, one that looks more like something you would find in other languages, and another that is more in line with the rest of the bash
syntax.
Before...