source: vendor/bash/3.1-p17/tests/trap.tests

Last change on this file was 3228, checked in by bird, 18 years ago

bash 3.1

File size: 1.1 KB
Line 
1# test the trap code
2
3trap 'echo exiting' 0
4trap '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
11trap
12
13func()
14{
15 trap 'echo ${FUNCNAME:-$0}[$LINENO] funcdebug' DEBUG
16 echo funcdebug line
17}
18
19trap 'echo [$LINENO] debug' DEBUG
20echo debug line
21
22trap
23
24func
25
26trap
27
28trap 'echo ${FUNCNAME:-$0}[$LINENO] debug' DEBUG
29func2()
30{
31 echo func2debug line
32}
33declare -ft func2
34func2
35
36unset -f func2
37
38trap '' DEBUG
39
40trap
41
42trap - debug
43
44trap
45
46trap - HUP
47trap hup
48trap '' INT
49trap '' int
50
51trap
52
53# exit 0 in exit trap should set exit status
54(
55set -e
56trap 'exit 0' EXIT
57false
58echo bad
59)
60echo $?
61
62# hmmm...should this set the handling to SIG_IGN for children, too?
63trap '' USR2
64./trap1.sub
65
66# test ERR trap
67./trap2.sub
68
69#
70# show that setting a trap on SIGCHLD is not disastrous.
71#
72set -o monitor
73
74trap 'echo caught a child death' SIGCHLD
75
76sleep 7 & sleep 6 & sleep 5 &
77
78wait
79
80trap -p SIGCHLD
81
82# Now reset some of the signals the shell handles specially back to
83# their default values (with or without the SIG prefix)
84trap - SIGINT QUIT TERM
85
86trap
Note: See TracBrowser for help on using the repository browser.