The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Trap jeenat Shell Programming and Scripting 1 04-07-2008 03:07 AM
trap command onlyc UNIX for Dummies Questions & Answers 3 07-11-2006 12:15 AM
Building a better mouse trap, or How many lines of code does it take to trap a mouse? mph Shell Programming and Scripting 4 04-06-2006 01:02 PM
trap whatisthis Shell Programming and Scripting 9 04-11-2005 01:39 PM
Need help with trap marc6057 UNIX for Advanced & Expert Users 7 10-23-2001 12:45 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-11-2007
Registered User
 

Join Date: Jul 2007
Posts: 2
Question Need help with trap

Hi

Our problem is knowing:

What is the "best" way of simulating a TRAP for ERR within a function, since we know this will not work directly with ksh93 and aix5. How can we save the error encountered in the function and then deal with it in the calling script?

Thanks!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-11-2007
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,322
How about echoing the error in the function?
Code:
function() {
   # some code
   echo $?   # $? contains the return value of the command
}

return_value=function
if [ $return_value -ne 0 ]; then
   # deal with error
fi
Reply With Quote
  #3 (permalink)  
Old 07-12-2007
Registered User
 

Join Date: Jul 2007
Posts: 2
Red face More about TRAP for ERR in aix

Thanx,

That helps but could be "messy" if function is complicated. We found that the original TRAP for ERR inside functions is actually fixed in later versions of AIX 5.

Also, If the function is dotted the TRAP for ERR will work in our version of AIX. Is it "normal" to dot functions?

Cheers
Reply With Quote
  #4 (permalink)  
Old 07-12-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,333
Quote:
Originally Posted by theteeth07 View Post
We found that the original TRAP for ERR inside functions is actually fixed in later versions of AIX 5.
If you are struggling with a broken version of ksh you should upgrade to the version you know to be fixed. Your buggy ksh may have more bugs you have not yet discovered.

Quote:
Originally Posted by theteeth07 View Post
Is it "normal" to dot functions?
No.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




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


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

Content Relevant URLs by vBSEO 3.2.0