0

In a bash interactive shell, when I run a trap command (e.g. trap "echo You hit control-C!" INT) to set up a signal handler, does that set up how the bash interactive shell handles the signal?

How can I test that the bash interactive shell handles the signal by using the handler that I set up via trap?

Is it possible to test i.e. to generate the signal

  • within the bash interactive shell?
  • within the terminal emulator where the shell runs?

Or must I test from the outside of the bash interactive shell, or outside the terminal emulator?

Thanks.

2
  • What do you expect to happen, and what's happening instead? The definition of trap is "The commands in arg are to be read and executed when the shell receives signal sigspec."
    – Jeff Schaller
    Oct 19, 2017 at 23:38
  • I would like to know how to show that an interactive shell reacts to a signal for which a trap has been set in it.
    – Tim
    Oct 20, 2017 at 1:17

1 Answer 1

3

You can test a handler from inside the shell it’s set up in, by using kill to send a signal to the current shell:

kill -INT $$

Change -INT to match the trap you wish to test.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .