Imported from ../bash-2.05.tar.gz.
[platform/upstream/bash.git] / tests / set-e-test
1 if : ; 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
16 fi
17
18 (
19 set -e
20 false
21 echo bad
22 )
23 echo $?
24
25 x=$(
26 set -e
27 false
28 echo bad
29 )
30 echo $? $x
31
32 # command subst should not inherit -e
33 set -e
34 echo $(false; echo ok)
35
36 if set +e
37 then
38         false
39 fi
40 echo hi
41
42 set -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
47 while false; do
48         echo hi
49 done
50 echo while succeeded
51
52 x=1
53 until (( x == 4 )); do
54         x=4
55 done
56 echo until succeeded: $x
57
58 if false; then
59         echo oops
60 fi
61 echo if succeeded
62
63 # failing commands that are part of an AND or OR list should not
64 # cause the shell to exit
65 false && echo AND list failed
66 echo AND list succeeded
67
68 false || echo OR list succeeded
69
70 ! false
71 echo ! succeeded
72
73 # make sure eval preserves the state of the -e flag and `!' reserved word
74 set -e
75 if eval false; then
76         echo oops
77 fi
78 echo eval succeeded
79
80 ! eval false
81 echo ! eval succeeded -- 1
82
83 ! eval '(exit 5)'
84 echo ! eval succeeded -- 2