LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (http://www.linuxquestions.org/questions/red-hat-31/)
-   -   return value of function in script (http://www.linuxquestions.org/questions/red-hat-31/return-value-of-function-in-script-530162/)

ramesh_manu 02-18-2007 12:20 PM

return value of function in script
 
How can i return value of function in bash shell scrit ? I used the S? for obtaining return value. But it does not exceed the 256 limit.


pow( )
{
------
------
return $ans
}

read a
read b
pow $a, $b
echo "the result is $?"

wmakowski 02-18-2007 02:05 PM

The exit status from functions in bash or other shell scripting languages are not meant to be used like values returned from C functions. While it is possible to do what you suggested. You should use variables or command substitution instead. The exit status obtained using $? is used mainly for flow control. In other words, the function worked do this, otherwise do this.

You may want to post questions like this to the Programming forum where they will get better exposure. This is not specific to RedHat.

Bill


All times are GMT -5. The time now is 09:30 AM.