Imported from ../bash-2.05a.tar.gz.
[platform/upstream/bash.git] / tests / trap.tests
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
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
52 # hmmm...should this set the handling to SIG_IGN for children, too?
53 trap '' USR2
54 ./trap1.sub
55
56 # test ERR trap
57 ./trap2.sub
58
59 #
60 # show that setting a trap on SIGCHLD is not disastrous.
61 #
62 set -o monitor
63
64 trap 'echo caught a child death' SIGCHLD
65
66 sleep 7 & sleep 6 & sleep 5 &
67
68 wait
69
70 trap -p SIGCHLD
71
72 # Now reset some of the signals the shell handles specially back to
73 # their default values (with or without the SIG prefix)
74 trap SIGINT QUIT TERM
75
76 trap
77