Hi . Most of the time we need to call a certain block of code multiple time. We group them together under a function and call it from where ever we need from main body of program. Here an example is shown on how to define and call a function in bash shell scripting.
#/usr/bin/bash function sub_function { echo "Statement printing from function block" } echo "Example of function" echo "Before function call" sub_function echo "After function call"
Output of above code snippet
> bash function.bash
Example of function
Before function call
Statement printing from function block
After function call
Comments
Post a Comment