x

Unix Shell functions

PREV     NEXT

Unix Shell functions:


  • Function is a series of instruction/commands. Function performs particular activity in shell i.e. it had specific work to do or simply say task.
  • When program gets complex we need to use divide and conquer technique. It means whenever programs gets complicated, we divide it into small chunks/entities which are known as functions.

Syntax:

Where function-name is name of your function, that executes series of commands. A return statement will terminate the function.


Ex1:

Output:

Note:

To execute this SayHello() function just type it name as mentioned in above example.

Ex2:

Output:

Note:

In the above example, the function “hai” has been called again after the “exit” statement. So, script did not execute the “hai” again. Whatever the function/commands called after the exit statement will not be executed.

PREV     NEXT



Like it? Please Spread the word!