Re: about return values
- From: Janis Papanagnou <Janis_Papanagnou@xxxxxxxxxxx>
- Date: Sun, 23 Apr 2006 15:06:07 +0200
dondora wrote:
hi there
first of all I wanna say thank you for answering my previous questions.
Okay~~!
I made a simple shell script like this below in ksh.
sigma ()
{
yo=$1
sum=0
while (( yo != 0 ))
do
(( sum = sum + yo))
(( yo = yo - 1))
done
return $sum
}
sigma 100
echo $?
but the result was 186 not 5050
I can't understand why it printed out like that. so Could you explain
it to me why it is???
It's already been answered two days ago...
Return values from functions have a limited range, one byte. Their purpose
is to return exit status codes (error codes), not arithmetic values. Thus
the term "function" is to some extent a misnomer; consider shell functions
to be rather programs or procedures.
To return values from functions either use variables (the global variable
REPLY had been suggested) or let the function print the value and use the
form res=$( sigma ) to obtain the result.
Janis
.
- Follow-Ups:
- Re: about return values
- From: dondora
- Re: about return values
- References:
- about return values
- From: dondora
- about return values
- Prev by Date: about return values
- Next by Date: Re: about return values
- Previous by thread: about return values
- Next by thread: Re: about return values
- Index(es):
Relevant Pages
|