--- /dev/null
+a:2
+b:0
+Trap
+d:3
--- /dev/null
+a() {
+ (exit 2)
+ echo a:$?
+ (kill -s USR1 $$; echo b:$?; exit 3)
+ echo c:$? # does not execute
+ (exit 4)
+}
+
+trap "echo Trap; return" USR1
+a
+
+echo d:$?
+# It's debatable what is the correct value above.
+# Does 'return' in trap sees $? == 2 or $? == 3?
+# IOW: after (kill..), does shell first wait for its completion
+# and sets $?, then checks pending signals and runs a trap handler,
+# or does it first checks pending signals and runs handler?
+# hush does the former, and prints 3.
--- /dev/null
+sending USR2
+caught
+sending USR2
+sending USR2
+USR2
--- /dev/null
+# avoid ugly warnings about signals not being caught
+trap ":" USR1 USR2
+
+"$THIS_SH" -c '
+trap "echo caught" USR2
+echo "sending USR2"
+kill -USR2 $$
+
+trap "" USR2
+echo "sending USR2"
+kill -USR2 $$
+
+trap "-" USR2
+echo "sending USR2"
+kill -USR2 $$
+
+echo "not reached"
+'
+
+trap "-" USR1 USR2
--- /dev/null
+cow
+moo
+Traps1:
+trap -- 'exitfunc' EXIT
+Traps2:
+trap -- 'echo Should not run' EXIT
+Check1: 42
+Traps1:
+trap -- 'exitfunc' EXIT
+Traps2:
+trap -- 'echo Should not run' EXIT
+Check2: 42
--- /dev/null
+"$THIS_SH" -c 'trap "echo cow" 0'
+"$THIS_SH" -c 'trap "echo moo" EXIT'
+"$THIS_SH" -c 'trap "echo no" 0; trap 0'
+
+(
+exitfunc() {
+ echo "Traps1:"
+ trap
+ # EXIT trap is disabled after it is triggered,
+ # it can not be "re-armed" like this:
+ trap "echo Should not run" EXIT
+ echo "Traps2:"
+ trap
+}
+trap 'exitfunc' EXIT
+exit 42
+)
+echo Check1: $?
+
+(
+exitfunc() {
+ echo "Traps1:"
+ trap
+ # EXIT trap is disabled after it is triggered,
+ # it can not be "re-armed" like this:
+ trap "echo Should not run" EXIT
+ echo "Traps2:"
+ trap
+ exit 42
+}
+trap 'exitfunc' EXIT
+exit 66
+)
+echo Check2: $?
--- /dev/null
+a:2
+b:0
+Trap
+d:3
--- /dev/null
+a() {
+ (exit 2)
+ echo a:$?
+ (kill -s USR1 $$; echo b:$?; exit 3)
+ echo c:$? # does not execute
+ (exit 4)
+}
+
+trap "echo Trap; return" USR1
+a
+
+echo d:$?
+# It's debatable what is the correct value above.
+# Does 'return' in trap sees $? == 2 or $? == 3?
+# IOW: after (kill..), does shell first wait for its completion
+# and sets $?, then checks pending signals and runs a trap handler,
+# or does it first checks pending signals and runs handler?
+# hush does the former, and prints 3.
--- /dev/null
+# make sure we do not corrupt $? across traps
+trap "echo YEAH; false" USR1
+kill -USR1 $$
+echo $?
--- /dev/null
+trap -- 'echo Exiting' EXIT
+trap -- 'echo WINCH!' WINCH
+trap -- 'echo Exiting' EXIT
+trap -- 'echo WINCH!' WINCH
+trap -- 'echo Exiting' EXIT
+trap -- 'echo WINCH!' WINCH
+Done
+Exiting
--- /dev/null
+trap 'echo Exiting' EXIT
+trap 'echo WINCH!' SIGWINCH
+v=` trap `
+echo "$v"
+v=$( trap )
+echo "$v"
+v=`trap`
+echo "$v"
+echo Done
--- /dev/null
+Bug detected: 0
--- /dev/null
+bug() {
+ trap : exit
+ # Bug was causing sh to be run in subshell,
+ # as if this line is replaced with (sh -c ...; exit $?) &
+ # here:
+ sh -c 'echo REAL_CHILD=$$' &
+ echo PARENTS_IDEA_OF_CHILD=$!
+ wait # make sure bkgd shell completes
+}
+
+bug | {
+while read varval; do
+ eval $varval
+done
+test x"$REAL_CHILD" != x"" \
+&& test x"$REAL_CHILD" = x"$PARENTS_IDEA_OF_CHILD"
+echo "Bug detected: $?"
+}
--- /dev/null
+(sleep 1; kill -HUP $$) &
+trap 'echo "Got HUP:$?"; exit' HUP
+while true; do
+ read ignored
+done
--- /dev/null
+HUP
+Done:129
--- /dev/null
+$THIS_SH -c '
+(sleep 1; kill -HUP $$) &
+while true; do
+ read ignored
+done
+'
+echo "Done:$?"
--- /dev/null
+trap -- '' HUP
+trap -- '' QUIT
+trap -- '' SYS
+Ok
+trap -- '' HUP
+trap -- '' QUIT
+trap -- '' SYS
+Ok
+trap -- '' HUP
+trap -- '' QUIT
+trap -- '' SYS
+Ok
+trap -- '' HUP
+trap -- '' QUIT
+trap -- '' SYS
+Ok
+trap -- '' HUP
+trap -- '' QUIT
+trap -- '' SYS
+TERM
+Done
--- /dev/null
+# Non-empty traps should be reset in subshell
+
+# HUP is special in interactive shells
+trap '' HUP
+# QUIT is always special
+trap '' QUIT
+# SYS is not special
+trap '' SYS
+# WINCH is harmless
+trap 'bad: caught WINCH' WINCH
+# With TERM we'll check whether it is reset
+trap 'bad: caught TERM' TERM
+
+(trap; "$THIS_SH" -c 'kill -HUP $PPID'; echo Ok)
+(trap; "$THIS_SH" -c 'kill -QUIT $PPID'; echo Ok)
+(trap; "$THIS_SH" -c 'kill -SYS $PPID'; echo Ok)
+(trap; "$THIS_SH" -c 'kill -WINCH $PPID'; echo Ok)
+(trap; "$THIS_SH" -c 'kill -TERM $PPID'; echo Bad: TERM is not reset)
+echo Done
--- /dev/null
+___
+___
+___
+trap -- 'a' EXIT
+trap -- 'a' INT
+trap -- 'a' USR1
+trap -- 'a' USR2
+___
+___
+trap -- 'a' USR1
+trap -- 'a' USR2
+___
+___
+trap -- 'a' USR2
--- /dev/null
+# no output -- default state
+echo ___
+trap
+
+# assign some traps
+echo ___
+trap "a" EXIT INT USR1 USR2
+
+# show them all
+echo ___
+trap
+
+# clear one
+echo ___
+trap 0 INT
+echo ___
+trap
+
+# clear another
+echo ___
+trap "-" USR1
+echo ___
+trap
+++ /dev/null
-sending USR2
-caught
-sending USR2
-sending USR2
-USR2
+++ /dev/null
-# avoid ugly warnings about signals not being caught
-trap ":" USR1 USR2
-
-"$THIS_SH" -c '
-trap "echo caught" USR2
-echo "sending USR2"
-kill -USR2 $$
-
-trap "" USR2
-echo "sending USR2"
-kill -USR2 $$
-
-trap "-" USR2
-echo "sending USR2"
-kill -USR2 $$
-
-echo "not reached"
-'
-
-trap "-" USR1 USR2
+++ /dev/null
-cow
-moo
-Traps1:
-trap -- 'exitfunc' EXIT
-Traps2:
-trap -- 'echo Should not run' EXIT
-Check1: 42
-Traps1:
-trap -- 'exitfunc' EXIT
-Traps2:
-trap -- 'echo Should not run' EXIT
-Check2: 42
+++ /dev/null
-"$THIS_SH" -c 'trap "echo cow" 0'
-"$THIS_SH" -c 'trap "echo moo" EXIT'
-"$THIS_SH" -c 'trap "echo no" 0; trap 0'
-
-(
-exitfunc() {
- echo "Traps1:"
- trap
- # EXIT trap is disabled after it is triggered,
- # it can not be "re-armed" like this:
- trap "echo Should not run" EXIT
- echo "Traps2:"
- trap
-}
-trap 'exitfunc' EXIT
-exit 42
-)
-echo Check1: $?
-
-(
-exitfunc() {
- echo "Traps1:"
- trap
- # EXIT trap is disabled after it is triggered,
- # it can not be "re-armed" like this:
- trap "echo Should not run" EXIT
- echo "Traps2:"
- trap
- exit 42
-}
-trap 'exitfunc' EXIT
-exit 66
-)
-echo Check2: $?
+++ /dev/null
-a:2
-b:0
-Trap
-d:3
+++ /dev/null
-a() {
- (exit 2)
- echo a:$?
- (kill -s USR1 $$; echo b:$?; exit 3)
- echo c:$? # does not execute
- (exit 4)
-}
-
-trap "echo Trap; return" USR1
-a
-
-echo d:$?
-# It's debatable what is the correct value above.
-# Does 'return' in trap sees $? == 2 or $? == 3?
-# IOW: after (kill..), does shell first wait for its completion
-# and sets $?, then checks pending signals and runs a trap handler,
-# or does it first checks pending signals and runs handler?
-# hush does the former, and prints 3.
+++ /dev/null
-# make sure we do not corrupt $? across traps
-trap "echo YEAH; false" USR1
-kill -USR1 $$
-echo $?
+++ /dev/null
-trap -- 'echo Exiting' EXIT
-trap -- 'echo WINCH!' WINCH
-trap -- 'echo Exiting' EXIT
-trap -- 'echo WINCH!' WINCH
-trap -- 'echo Exiting' EXIT
-trap -- 'echo WINCH!' WINCH
-Done
-Exiting
+++ /dev/null
-trap 'echo Exiting' EXIT
-trap 'echo WINCH!' SIGWINCH
-v=` trap `
-echo "$v"
-v=$( trap )
-echo "$v"
-v=`trap`
-echo "$v"
-echo Done
+++ /dev/null
-Bug detected: 0
+++ /dev/null
-bug() {
- trap : exit
- # Bug was causing sh to be run in subshell,
- # as if this line is replaced with (sh -c ...; exit $?) &
- # here:
- sh -c 'echo REAL_CHILD=$$' &
- echo PARENTS_IDEA_OF_CHILD=$!
- wait # make sure bkgd shell completes
-}
-
-bug | {
-while read varval; do
- eval $varval
-done
-test x"$REAL_CHILD" != x"" \
-&& test x"$REAL_CHILD" = x"$PARENTS_IDEA_OF_CHILD"
-echo "Bug detected: $?"
-}
+++ /dev/null
-(sleep 1; kill -HUP $$) &
-trap 'echo "Got HUP:$?"; exit' HUP
-while true; do
- read ignored
-done
+++ /dev/null
-HUP
-Done:129
+++ /dev/null
-$THIS_SH -c '
-(sleep 1; kill -HUP $$) &
-while true; do
- read ignored
-done
-'
-echo "Done:$?"
+++ /dev/null
-trap -- '' HUP
-trap -- '' QUIT
-trap -- '' SYS
-Ok
-trap -- '' HUP
-trap -- '' QUIT
-trap -- '' SYS
-Ok
-trap -- '' HUP
-trap -- '' QUIT
-trap -- '' SYS
-Ok
-trap -- '' HUP
-trap -- '' QUIT
-trap -- '' SYS
-Ok
-trap -- '' HUP
-trap -- '' QUIT
-trap -- '' SYS
-TERM
-Done
+++ /dev/null
-# Non-empty traps should be reset in subshell
-
-# HUP is special in interactive shells
-trap '' HUP
-# QUIT is always special
-trap '' QUIT
-# SYS is not special
-trap '' SYS
-# WINCH is harmless
-trap 'bad: caught WINCH' WINCH
-# With TERM we'll check whether it is reset
-trap 'bad: caught TERM' TERM
-
-(trap; "$THIS_SH" -c 'kill -HUP $PPID'; echo Ok)
-(trap; "$THIS_SH" -c 'kill -QUIT $PPID'; echo Ok)
-(trap; "$THIS_SH" -c 'kill -SYS $PPID'; echo Ok)
-(trap; "$THIS_SH" -c 'kill -WINCH $PPID'; echo Ok)
-(trap; "$THIS_SH" -c 'kill -TERM $PPID'; echo Bad: TERM is not reset)
-echo Done
+++ /dev/null
-___
-___
-___
-trap -- 'a' EXIT
-trap -- 'a' INT
-trap -- 'a' USR1
-trap -- 'a' USR2
-___
-___
-trap -- 'a' USR1
-trap -- 'a' USR2
-___
-___
-trap -- 'a' USR2
+++ /dev/null
-# no output -- default state
-echo ___
-trap
-
-# assign some traps
-echo ___
-trap "a" EXIT INT USR1 USR2
-
-# show them all
-echo ___
-trap
-
-# clear one
-echo ___
-trap 0 INT
-echo ___
-trap
-
-# clear another
-echo ___
-trap "-" USR1
-echo ___
-trap