blob: 53ef0dd3877bd646f82bf0c7214faf46137c2f98 (
plain)
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
|
# `command` takes away the special properties of special builtins: an
# error inside them sets a status instead of exiting the shell.
command eval 'if' 2>/dev/null
echo "eval syntax: $?"
command . ./nonexistent 2>/dev/null
echo "dot missing: $?"
printf 'if\n' >bad.sh
command . ./bad.sh 2>/dev/null
echo "dot syntax: $?"
command eval 'x=$((1/0))' 2>/dev/null
echo "eval arith: $?"
f() {
command eval 'return 3'
echo not reached
}
f
echo "return through command eval: $?"
for i in 1 2; do
command eval break
echo "loop $i"
done
echo "after break"
# errors caught many times leave the shell usable (no leaked state)
i=0
while [ $i -lt 20 ]; do
command eval 'if' 2>/dev/null
command . ./bad.sh 2>/dev/null
i=$((i + 1))
done
echo "survived $i"
x=$(command eval 'if' 2>/dev/null; echo "in cmdsub $?")
echo "$x"
(command eval 'exit 4'; echo not reached)
echo "exit still exits: $?"
# without command, the error exits the shell
eval 'if' 2>/dev/null
echo not reached
|