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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.