What AreBash Functions?
Alike to other coding languages, Bash allows you to create functions from within your code or script.
Finally, we call the function welcome by simply using it’s name,welcome.
Shutterstock
The resulting output may look interesting, or even confusing at first.
However, it is logical and easy to follow.
“first”, and this why the first line of output is indeedfirst.
We then callfunc2and we pass two strings"a"and"b"to the function.
The output iscbaas can be expected by scanning over the code and noting the variable names etc.
However, the code is complex and takes a little getting used to.
First, we define a functionfunc3in which we create a local variable namedREVERSE.
Therevcommand prints the input received from the pipe (or otherwise) in reverse.
It is past integrally.
Next, still from within thefunc3function, we print the output.
Note that there is absolutely no connection between the’global’REVERSEvariable and thelocalREVERSEvariable inside the script.