When your bash scripts get bigger and bigger things can get very messy .
You may find yourself rewriting the same pieces of code again and again in different parts of your bash scripts. .
Luckily you can avoid rewriting code by using functions in bash which will make your scripts more organized and readable. .
In this tutorial you will learn to create functions return function values and pass function arguments in bash shell scripts. .
Furthermore you will learn how variables scope work and how to define recursive functions.
There are two different syntaxes for declaring bash functions. The following syntax is the most common used way of creating bash functions.
The second less commonly used of creating bash functions starts with the reserved work function followed by the function name as follows.
Now there are a couple of things you should be well aware of when working with functions.