8.6 Subroutine



In programming, a subroutine is a sequence of program instructions that perform a specific task for reuse.

The subroutine has various names by program languages, is called 'function' by shell script. A function receives the data called arguments and returns its results. The form is as follows.

Format

function function_name
{
    processing
}


function_name ()
{
    processing
}


Both are same. Arguments are described after function name at the time of execution. In program, arguments can be referred by $1, $2, ....


In function of shell script, return sentence is used for returning the result.


Format

return variable


‘return’ sentence ends the processing, and passes its result and control to origin.



Previous Next