Register
It is currently Wed Sep 03, 2014 1:01 am

how to pass argument to function called via "trap"


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Feb 17, 2009 1:09 pm   

Joined: Tue Feb 17, 2009 12:47 pm
Posts: 3
Hello -

I have a bash daemon with the following signal trap code:

trap shutdown_daemon $EXIT_SIGNAL SIGTERM SIGINT SIGHUP

Where:
shutdown_daemon is a function I am calling.
$EXIT_SIGNAL is a var that contains an argument that I want to pass to the function.
SIGTERM SIGINT SIGHUP are the signals I want to trap.

Current Behavior:
The function is called when a signal is trapped, but it does not receive an argument in $1. I'm guessing that trap sees the arg as just another signal number.

How can I pass an argument to a function called via the "trap" built-in? Is there some quoting magic that I am missing?

Thanks,

-js


Top
 Profile WWW  
 PostPosted: Tue Feb 17, 2009 2:52 pm   

Joined: Tue Feb 17, 2009 12:47 pm
Posts: 3
And the answer is wrap it in single quotes:

trap 'shutdown_daemon $EXIT_SIGNAL' SIGTERM SIGINT SIGHUP


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP