How to retrun a value from a function call

Hi
I have the following code - It returns a value but I don't know how to access it in the main code!!!

#!/usr/bin/ksh
set +x
function f {
d=`date +"%H%M%S`
typeset -Z8 x
x=$RANDOM
i="$d""$x"$$
return $i #<-- i need to access this value!!!
}

echo $f #<-- How to show the returned value here???

exit 0

Thanks.

$? holds the exit status of the last command executed. Return will exit a function with a status of x (assuming you exit the function using return x). If x is not supplied, return will return the exit status of the last command executed. So, in your shell script, call the function, inside the function, use return x. Just after the function call, evaluate $? for the value contained in the return statement.
or
Call the function and evaluate the variable $i to see its contents. Change your echo $f to echo $i to see what the variable i contains after the function is called.

You can't do that. From the ksh man page:

The value you are attempting to return is quite a bit more than 8 bits.

Thanks for your help guys.

I guess the fact that the number bieng returned is longer than 8 bits is causing a problem, as I am getting a 'bad number' on the return statement.

I will use the variable set inside the function instead.

Thanks again. :slight_smile:

You could also try this:

function foo
{
    print "My Return Value"
}
x=$(foo)

print $x