Trap question
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Trap question




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Trap question  
Jeff


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-22-07 06:16 PM

Can someone answer this question about TRAP.  I have trap specified
in the main shell for the correct exits to remove some tmp files.  My
shell calles a function, if there is a error within the called function
the trap does not remove the files.  If I specify the trap within the
function that errors the files are removed corectly.  I beleived that
trap in the main should know there was a exit in the function and
remove the files.  Why does trap in the main not know a function failed
and remove the files?  Thanks in advance.  We are running the shell on
a sun server.






[ Post a follow-up to this message ]



    Re: Trap question  
Logan Shaw


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-07 12:31 PM

Jeff wrote:
>   Can someone answer this question about TRAP.  I have trap specified
> in the main shell for the correct exits to remove some tmp files.  My
> shell calles a function, if there is a error within the called function
> the trap does not remove the files.  If I specify the trap within the
> function that errors the files are removed corectly.  I beleived that
> trap in the main should know there was a exit in the function and
> remove the files.  Why does trap in the main not know a function failed
> and remove the files?

You'll have to give some more information.  I tried to duplicate your
problem on Solaris 8[1] and couldn't see any problem like what you are
describing.  Here's what I tried:

$ uname -sr
SunOS 5.8
$ cat /tmp/foo.sh
#! /bin/sh

trap 'rm /tmp/abc' 0

foo ()
{
exit 1
}

touch /tmp/abc
file /tmp/abc
foo
$ /tmp/foo.sh
/tmp/abc:       empty file
$ file /tmp/abc
/tmp/abc:       cannot open: No such file or directory
$

So, it would appear that calling exit from inside a function still
causes the trap code to run.

- Logan

[1]  x86 edition, but it should hardly matter since well over 90% of the
code is identical, including probably all of the shell code.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:46 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register