]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/set-e-test
Imported from ../bash-2.05.tar.gz.
[thirdparty/bash.git] / tests / set-e-test
CommitLineData
726f6388
JA
1if : ; then
2 set -e
3 N=95
4 while :; do
5 # expr returns 1 if expression is null or 0
6 set +e
7 N_MOD_100=`expr $N % 100`
8 set -e
9 echo $N_MOD_100
10 N=`expr $N + 1`
11 if [ $N -eq 110 ]; then
12 break
13 fi
14 done
15 set +e
16fi
28ef6c31
JA
17
18(
19set -e
20false
21echo bad
22)
23echo $?
24
25x=$(
26set -e
27false
28echo bad
29)
30echo $? $x
31
ccc6cda3
JA
32# command subst should not inherit -e
33set -e
34echo $(false; echo ok)
d166f048
JA
35
36if set +e
37then
38 false
39fi
40echo hi
41
42set -e
43
44# a failing command in the compound list following a while, until, or
45# if should not cause the shell to exit
46
47while false; do
48 echo hi
49done
50echo while succeeded
51
52x=1
53until (( x == 4 )); do
54 x=4
55done
56echo until succeeded: $x
57
58if false; then
59 echo oops
60fi
61echo if succeeded
62
63# failing commands that are part of an AND or OR list should not
64# cause the shell to exit
65false && echo AND list failed
66echo AND list succeeded
67
68false || echo OR list succeeded
69
70! false
71echo ! succeeded
72
73# make sure eval preserves the state of the -e flag and `!' reserved word
74set -e
75if eval false; then
76 echo oops
77fi
78echo eval succeeded
79
80! eval false
81echo ! eval succeeded -- 1
82
83! eval '(exit 5)'
84echo ! eval succeeded -- 2