]>
Commit | Line | Data |
---|---|---|
d166f048 JA |
1 | # test the trap code |
2 | ||
3 | trap 'echo exiting' 0 | |
4 | trap 'echo aborting' 1 2 3 6 15 | |
5 | ||
6 | # make sure a user-specified subshell runs the exit trap, but does not | |
7 | # inherit the exit trap from a parent shell | |
8 | ( trap 'echo subshell exit' 0; exit 0 ) | |
9 | ( exit 0 ) | |
10 | ||
11 | trap | |
12 | ||
13 | func() | |
14 | { | |
15 | trap 'echo [$LINENO] funcdebug' DEBUG | |
16 | echo funcdebug line | |
17 | } | |
18 | ||
19 | trap 'echo [$LINENO] debug' DEBUG | |
20 | echo debug line | |
21 | ||
22 | trap | |
23 | ||
24 | func | |
25 | ||
26 | trap | |
27 | ||
28 | trap '' DEBUG | |
29 | ||
30 | trap | |
31 | ||
32 | trap - debug | |
33 | ||
34 | trap | |
35 | ||
36 | trap - HUP | |
37 | trap hup | |
38 | trap '' INT | |
39 | trap '' int | |
40 | ||
41 | trap | |
42 | ||
28ef6c31 JA |
43 | # exit 0 in exit trap should set exit status |
44 | ( | |
45 | set -e | |
46 | trap 'exit 0' EXIT | |
47 | false | |
48 | echo bad | |
49 | ) | |
50 | echo $? | |
51 | ||
d166f048 JA |
52 | # hmmm...should this set the handling to SIG_IGN for children, too? |
53 | trap '' USR2 | |
cce855bc | 54 | ./trap1.sub |
d166f048 JA |
55 | |
56 | # | |
57 | # show that setting a trap on SIGCHLD is not disastrous. | |
58 | # | |
59 | set -o monitor | |
60 | ||
61 | trap 'echo caught a child death' SIGCHLD | |
62 | ||
63 | sleep 7 & sleep 6 & sleep 5 & | |
64 | ||
65 | wait | |
66 | ||
67 | trap -p SIGCHLD | |
cce855bc JA |
68 | |
69 | # Now reset some of the signals the shell handles specially back to | |
70 | # their default values (with or without the SIG prefix) | |
71 | trap SIGINT QUIT TERM | |
72 | ||
73 | trap |