bash functions bash function arguments

Bash functions bash function arguments

Bash functions

functions in bash used to perform repetitive tasks , we can put all task or command in one function and we can used it by just calling function name.

Creating Functions

syntax

functionName () {
list of commands
}

Output

Bash function arguments

Output

Returning Values from Functions

Output

Nested Functions

Nested function is function within function

Example

Output

Explanation : in the above example we can see that we only called FunctionOne and then FunctionOne called to FunctionTwo

Bonus Example script of function in bash

In below script we have created some function to get the Total size of RAM, CPU details ,Total core of CPU and Ubuntu Server version, we are using case for menu selection.

Note: In case *) is for value which is not match in case value.


You May Also Enjoy Reading This …

Leave a Reply

Your email address will not be published. Required fields are marked *