]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/set-e.tests
Bash-5.2-rc4 release
[thirdparty/bash.git] / tests / set-e.tests
CommitLineData
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
14if : ; 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
29fi
28ef6c31
JA
30
31(
32set -e
33false
34echo bad
35)
36echo $?
37
38x=$(
39set -e
40false
41echo bad
42)
43echo $? $x
44
ccc6cda3
JA
45# command subst should not inherit -e
46set -e
47echo $(false; echo ok)
d166f048
JA
48
49if set +e
50then
51 false
52fi
53echo hi
54
55set -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
60while false; do
61 echo hi
62done
63echo while succeeded
64
65x=1
66until (( x == 4 )); do
67 x=4
68done
69echo until succeeded: $x
70
71if false; then
72 echo oops
73fi
74echo if succeeded
75
76# failing commands that are part of an AND or OR list should not
77# cause the shell to exit
78false && echo AND list failed
79echo AND list succeeded
80
81false || echo OR list succeeded
82
83! false
84echo ! succeeded
85
86# make sure eval preserves the state of the -e flag and `!' reserved word
87set -e
88if eval false; then
89 echo oops
90fi
91echo eval succeeded
92
93! eval false
94echo ! eval succeeded -- 1
95
96! eval '(exit 5)'
97echo ! eval succeeded -- 2
3185942a
JA
98
99set -e
100until builtin false; do echo a; break; done
101echo $?
102
103until eval false; do echo b; break; done
104echo $?
105
106: ${TMPDIR:=/tmp}
107FN=$TMPDIR/set-e-$$
108cat > $FN << EOF
109false
110echo after 1
111false
112EOF
113
114set -e
115until . $FN; do echo a; break; done
116echo $?
117
118rm -f $FN
17345e5a
JA
119
120set +e
121
122${THIS_SH} ./set-e1.sub
123${THIS_SH} ./set-e2.sub
ac50fbac 124${THIS_SH} ./set-e3.sub