Re: return values from a function call
- From: Dave Kelly <daveekelly@xxxxxxxxxxxxx>
- Date: Sun, 29 Oct 2006 01:56:04 GMT
Janis Papanagnou wrote:
Dave Kelly wrote:paintedjazz@xxxxxxxxx wrote:
If I use the result of a function call in a condtional statement,
is it possible to return one of three possible values or is it just
true or false or a 0 or 1 status?
I want to test if a number is greater than, equal to or less than
another number.
Thus, the function should be something like:
if myfunction $num $another_num # return value is probably only 0 or
1
then
echo $num is greater than
else
echo $num is less than
fi
But I need to know if $num and $another_num are equal too.
Can I just have the function return a value (other than the status)
that could be tested?
How could I do that? Thx for your help.
I don't know if this would work, but I'd type it in and test it.
if ( a < b ) ? -1 : ( a == b ) ? 0 : 1 ;
Or is this one of those thing that is NOT portable anywhere except inside my head?
Don't know which shell supports your syntax. In ksh93 you can write...
x=$(( (a < b)? -1 : (a == b)? 0 : 1 ))
I don't know which shell supports it either. I wrote it using an example from my K&R C language book.
The OP does not have to use, minus one, zero, one. He can use any value that will fit in 'a' or 'b'. Does this take on the same type as in C code?
And does this fill the need of the OP?
.
- References:
- return values from a function call
- From: paintedjazz
- Re: return values from a function call
- From: Dave Kelly
- Re: return values from a function call
- From: Janis Papanagnou
- return values from a function call
- Prev by Date: Re: Using the grep command to filter
- Next by Date: Re: Using the grep command to filter
- Previous by thread: Re: return values from a function call
- Next by thread: Bash Adding 09 or 9.1 etc
- Index(es):
Relevant Pages
|