Listing traps

Let's reassign our function to signals with the trap command:

    $ trap 'echo "You pressed Control key" '  0 1 2 15

If we do not pass any arguments after the trap command, then it lists all reassigned signals along with their functions.

We can list all the assigned signal lists with the following command:

    $ trap

Output:

    trap -- 'echo "You pressed Control key" ' EXIT
    trap -- 'echo "You pressed Control key" ' SIGHUP
    trap -- 'echo "You pressed Control key" ' SIGINT
    trap -- 'echo "You pressed Control key" ' SIGTERM

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.