]>
Commit | Line | Data |
---|---|---|
8868edaf CR |
1 | # This program is free software: you can redistribute it and/or modify |
2 | # it under the terms of the GNU General Public License as published by | |
3 | # the Free Software Foundation, either version 3 of the License, or | |
4 | # (at your option) any later version. | |
5 | # | |
6 | # This program is distributed in the hope that it will be useful, | |
7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 | # GNU General Public License for more details. | |
10 | # | |
11 | # You should have received a copy of the GNU General Public License | |
12 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
13 | # | |
726f6388 JA |
14 | if : ; then |
15 | set -e | |
16 | N=95 | |
17 | while :; do | |
18 | # expr returns 1 if expression is null or 0 | |
19 | set +e | |
20 | N_MOD_100=`expr $N % 100` | |
21 | set -e | |
22 | echo $N_MOD_100 | |
23 | N=`expr $N + 1` | |
24 | if [ $N -eq 110 ]; then | |
25 | break | |
26 | fi | |
27 | done | |
28 | set +e | |
29 | fi | |
28ef6c31 JA |
30 | |
31 | ( | |
32 | set -e | |
33 | false | |
34 | echo bad | |
35 | ) | |
36 | echo $? | |
37 | ||
38 | x=$( | |
39 | set -e | |
40 | false | |
41 | echo bad | |
42 | ) | |
43 | echo $? $x | |
44 | ||
ccc6cda3 JA |
45 | # command subst should not inherit -e |
46 | set -e | |
47 | echo $(false; echo ok) | |
d166f048 JA |
48 | |
49 | if set +e | |
50 | then | |
51 | false | |
52 | fi | |
53 | echo hi | |
54 | ||
55 | set -e | |
56 | ||
57 | # a failing command in the compound list following a while, until, or | |
58 | # if should not cause the shell to exit | |
59 | ||
60 | while false; do | |
61 | echo hi | |
62 | done | |
63 | echo while succeeded | |
64 | ||
65 | x=1 | |
66 | until (( x == 4 )); do | |
67 | x=4 | |
68 | done | |
69 | echo until succeeded: $x | |
70 | ||
71 | if false; then | |
72 | echo oops | |
73 | fi | |
74 | echo if succeeded | |
75 | ||
76 | # failing commands that are part of an AND or OR list should not | |
77 | # cause the shell to exit | |
78 | false && echo AND list failed | |
79 | echo AND list succeeded | |
80 | ||
81 | false || echo OR list succeeded | |
82 | ||
83 | ! false | |
84 | echo ! succeeded | |
85 | ||
86 | # make sure eval preserves the state of the -e flag and `!' reserved word | |
87 | set -e | |
88 | if eval false; then | |
89 | echo oops | |
90 | fi | |
91 | echo eval succeeded | |
92 | ||
93 | ! eval false | |
94 | echo ! eval succeeded -- 1 | |
95 | ||
96 | ! eval '(exit 5)' | |
97 | echo ! eval succeeded -- 2 | |
3185942a JA |
98 | |
99 | set -e | |
100 | until builtin false; do echo a; break; done | |
101 | echo $? | |
102 | ||
103 | until eval false; do echo b; break; done | |
104 | echo $? | |
105 | ||
106 | : ${TMPDIR:=/tmp} | |
107 | FN=$TMPDIR/set-e-$$ | |
108 | cat > $FN << EOF | |
109 | false | |
110 | echo after 1 | |
111 | false | |
112 | EOF | |
113 | ||
114 | set -e | |
115 | until . $FN; do echo a; break; done | |
116 | echo $? | |
117 | ||
118 | rm -f $FN | |
17345e5a JA |
119 | |
120 | set +e | |
121 | ||
122 | ${THIS_SH} ./set-e1.sub | |
123 | ${THIS_SH} ./set-e2.sub | |
ac50fbac | 124 | ${THIS_SH} ./set-e3.sub |