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