blob: 25e78ffe34423721a1e882e6647d415c7236b918 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# An error the shell catches (`command eval`) must leave no trace of the
# command that failed: not its variables, not a redirection it had in force,
# not the text it was reading. The state is put back before the jump, while
# the frames that own it still exist.
f() { x=1; echo "${u?boom}"; }
command eval f >/dev/null 2>&1
echo "vars: [$x]"
# f's stdout redirection must be undone with the error
g() { echo "${u?boom}" >/dev/null; }
command eval g 2>/dev/null
echo "stdout is back"
# the eval text is not read again
h() { echo "${u?boom}"; }
command eval 'h; echo not reached' 2>/dev/null
echo "input is back"
# and it still works after many such errors
i=0
while [ $i -lt 50 ]; do
command eval f >/dev/null 2>&1
i=$((i + 1))
done
echo "survived $i"
|