]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/trap.tests
Bash-4.4 patch 19
[thirdparty/bash.git] / tests / trap.tests
CommitLineData
d166f048
JA
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{
7117c2d2 15 trap 'echo ${FUNCNAME:-$0}[$LINENO] funcdebug' DEBUG
d166f048
JA
16 echo funcdebug line
17}
18
19trap 'echo [$LINENO] debug' DEBUG
20echo debug line
21
22trap
23
24func
25
26trap
27
7117c2d2
JA
28trap 'echo ${FUNCNAME:-$0}[$LINENO] debug' DEBUG
29func2()
30{
31 echo func2debug line
32}
33declare -ft func2
34func2
35
36unset -f func2
37
d166f048
JA
38trap '' DEBUG
39
40trap
41
42trap - debug
43
44trap
45
46trap - HUP
47trap hup
48trap '' INT
49trap '' int
50
51trap
52
28ef6c31
JA
53# exit 0 in exit trap should set exit status
54(
55set -e
56trap 'exit 0' EXIT
57false
58echo bad
59)
60echo $?
61
d166f048
JA
62# hmmm...should this set the handling to SIG_IGN for children, too?
63trap '' USR2
cce855bc 64./trap1.sub
a0c0a00f 65trap - USR2
d166f048 66
f73dda09
JA
67# test ERR trap
68./trap2.sub
69
0001803f
CR
70${THIS_SH} ./trap3.sub
71
ac50fbac
CR
72${THIS_SH} ./trap4.sub
73
74# This doesn't work right on all Unix versions
75#${THIS_SH} ./trap5.sub
76
d166f048
JA
77#
78# show that setting a trap on SIGCHLD is not disastrous.
79#
80set -o monitor
81
82trap 'echo caught a child death' SIGCHLD
83
84sleep 7 & sleep 6 & sleep 5 &
85
3185942a 86# this will only catch the first, since there's a trap on SIGCHLD
d166f048
JA
87wait
88
89trap -p SIGCHLD
cce855bc
JA
90
91# Now reset some of the signals the shell handles specially back to
92# their default values (with or without the SIG prefix)
b80f6443 93trap - SIGINT QUIT TERM
cce855bc
JA
94
95trap
3185942a
JA
96
97trap - SIGCHLD
98wait