]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/trap4.sub
bash-4.3-beta overlay
[thirdparty/bash.git] / tests / trap4.sub
CommitLineData
1a81420a
CR
1# make sure subshells at the end of pipelines run any exit traps they set
2
3: | { trap 'echo exit subshell 1' EXIT; exit; }; echo current shell
4
5: | { trap 'echo exit subshell 2' EXIT; exit; }; echo current shell
6
7: | { trap 'echo exit subshell 3' EXIT; exit; } | : ; echo current shell
8
9: | { trap 'echo exit subshell 4' EXIT; exit; } | : ; echo current shell
10
11trap 'echo inherited exit trap' EXIT
12: | { exit; } ; echo outside 1
13: | ( exit; ) ; echo outside 2
14: | { exit; } | : ; echo outside 3
15: | ( exit; ) | : ; echo outside 4
16
17trap - EXIT
1442f67c
CR
18
19# make sure group commands that are not at the beginning or end of pipelines
20# run an EXIT trap, with and without the exit builtin
21echo ignored |
22{
23 trap 'echo "in trap EXIT">&2' EXIT
24 sleep 4 &
25 echo 'sleep 2'>&2
26 sleep 2
27 echo 'wait $!'>&2
28 wait $!
29 echo 'exit'>&2
30 exit
31} | cat
32
33echo ignored |
34{
35 trap 'echo "in trap EXIT">&2' EXIT
36 sleep 4 &
37 echo 'sleep 2'>&2
38 sleep 2
39 echo 'wait $!'>&2
40 wait $!
41 echo 'exit'>&2
42} | cat