So far in the book, we have mentioned that function is a reserved word and only used in Bash scripts that are in a single procedure, but what is a function?
To illustrate what a function is, first we need to define what a function is—a function is a self-contained section of code that performs a single task. However, a function performing a task may also execute many subtasks in order to complete its main task.
For example, you could have a function called file_creator that performs the following tasks:
- Check to see whether a file exists.
- If the file exists, truncate it. Otherwise, create a new one.
- Apply the correct permissions.
A function can also be passed parameters. Parameters are like variables that ...