Re: return values from a function call
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Fri, 27 Oct 2006 22:08:32 -0400
On 2006-10-28, 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.
A function can return any value from 0 to 255.
myfunction $num $another_num
case $? in
0) echo success; : ... ;;
1) echo returned 1; : .... ;;
....
255) : .... ;;
esac
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.
- References:
- return values from a function call
- From: paintedjazz
- return values from a function call
- Prev by Date: return values from a function call
- Next by Date: Re: return values from a function call
- Previous by thread: return values from a function call
- Next by thread: Re: return values from a function call
- Index(es):
Relevant Pages
|