1
sigusr1() { echo $1;}
trap sigusr1  SIGUSR1

I'm a bash newbie!

I have the above trap and signal code in my .bash_profile.To trigger sigusr1, i simply call Kill -SIGUSR1 pid in the terminal. I googled to find out how I can pass in a parameter into sigusr1 but I can't find anything except for if i use it as trap 'sigusr1 hello' SIGUSR1

But that defeat the purpose. I would like to pass in the parameter via the terminal. How can I pass in a parameter via the kill command so that sigusr1 function can echo it out?

Jolta
  • 2,620
  • 1
  • 29
  • 42
ytbryan
  • 2,644
  • 31
  • 49
  • 3
    I don't believe you can do this. Why do you want to? What are you trying to do exactly? – Etan Reisner Jan 19 '15 at 14:37
  • @etanReisner oops, sorry i miss your comment. I use this technique to create this rubygem https://rubygems.org/gems/aka2. It reloads dotfile after I edit it programatically. – ytbryan Feb 22 '17 at 09:23

1 Answers1

-1

To pass a parameter to function called by trap, change your trap call to:

trap 'sigusr1 $(cat ~/sigusr1-args)' SIGUSR1

Send the signal like this:

echo arg1 > ~/sigusr1-args;kill -SIGUSR1 PID
Quip Yowert
  • 444
  • 2
  • 7