Korn shell Tutorials :Writing Functions

Korn shell Tutorials :Writing Functions
Description
A function (= procedure) must be defined before it is called, because ksh is interpreted at run time.
It knows all the variables from the calling shell except the commandline arguments. But has it's
own command line arguments so that one can call it with different values from different places in
the script. It has an exit status but cannot return a value like a c funcition can.
Making a Function
One can make one in either of the following two ways:
function foo {
# commands...
}
foo(){
# commands...
}
Calling the Function
To call it just put it's name in the script: foo. To give it arguments do: foo arg1 arg2 ...
The arguments are there in the form of $1...$n and $* for all at once like in the main code.
And the main $1 is not influenced bye the $1 of a particular function.
Return
The return statement exits the function imediately with the specified return value as an exit status.

No comments: