How to create & use functions in shell scripts.
A function in shell scripting is written to divide entire code into small blocks or to dedicate a set of code for specific purpose just in the same way as it’s used in other programming languages like c, c++, python etc.
Function calling can be done, wherever required.
For e.g. - Let’s see below code for simple function calling.
#! /bin/bash
mytestfunc()
{
echo “Calling successfull”
}
###Main script
echo "Testing function calling"
mytestfunc
Below is the output -:
[root@localhost opt]# ./test.sh
testing function calling
“Hi this is my test function, tested OK ”
The above program shows and confirms function creation & calling.