Hi All,
just wanted to ask if functions created in a Korn shell script can be passed parameters and if so what is the syntax for creating a function with parameters?
thanks
Mani
Hi All,
just wanted to ask if functions created in a Korn shell script can be passed parameters and if so what is the syntax for creating a function with parameters?
thanks
Mani
Yes - example
myfunction()
{
echo "$1 $2"
}
myfunction "This is parameter 1" " Another parameter"
myfunction 32 64
You call the function with a list of parms, inside the function the parms are identified by $n where n is the number of the parameter.
thanks for the speedy response
could it also return a single value if i used a return statement i.e. return $x ?
I have tried it but doesn't seem to work.
Mani
Return statement is used to return an exit value from a shell function to the calling script.
To return string use echo statement.
myfunction()
{
echo "$1"
}
str=$( myfunction "This is parameter 1" " Another parameter")
echo $str