LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
Search this Thread
Old 02-18-2007, 11:20 AM   #1
ramesh_manu
LQ Newbie
 
Registered: Dec 2006
Location: chennai, India
Distribution: redhat & mandriva
Posts: 17

Rep: Reputation: 0
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 $?"
 
Old 02-18-2007, 01:05 PM   #2
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 18, 19, RHL 5.2
Posts: 546

Rep: Reputation: 43
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can a C function return value to Shell Script variable yarnar Programming 17 06-02-2010 05:54 PM
getting the return value from a thread start function cynthia_thomas Programming 1 02-18-2006 08:23 AM
using return in recursive function hubabuba Programming 9 10-10-2005 09:59 AM
can a function return a string? hubabuba Programming 13 03-06-2005 02:51 PM
PHP Function to return the most recent error. id10t Programming 5 05-30-2004 06:24 PM


All times are GMT -5. The time now is 03:38 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration