The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
function return array dophine Shell Programming and Scripting 6 05-06-2008 09:16 AM
Function call not return value into var katzs500 UNIX for Advanced & Expert Users 4 04-21-2008 10:27 AM
Function call not return value into var katzs500 UNIX for Dummies Questions & Answers 1 04-18-2008 06:31 PM
ORACLE return a function to Solaris Rafael.Buria Shell Programming and Scripting 1 10-23-2007 02:38 PM
return value of a function prez Shell Programming and Scripting 3 08-22-2007 02:08 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Posts: 17
Smile need to return value from function

how to return value from function and print from main program???
And also I need to return true or false... Is it possible?
Reply With Quote
Forum Sponsor
  #2  
Old 05-13-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Sure you can do both, just like from any shell script. Output is output and exit / return status is a different thing.

Code:
myfunc () {
  echo Fnord
  return 42
}
Reply With Quote
  #3  
Old 05-13-2008
sysgate's Avatar
Unix based
 

Join Date: Nov 2006
Location: /root
Posts: 1,200
It's certainly possible, which is the language in use ?
Reply With Quote
  #4  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Posts: 17
I m working in Perl.
Reply With Quote
  #5  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Posts: 17
and also want to print the returned value.
Reply With Quote
  #6  
Old 05-14-2008
sysgate's Avatar
Unix based
 

Join Date: Nov 2006
Location: /root
Posts: 1,200
If it's used in sub routine, use "return" function, otherwise printing the last value can be done with 'print "$variable_name\n"'
Also, you can always define custom return codes and strings, and print them when matching certain conditions.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0