1 ## compare_shells: dash bash zsh mksh ash yash
2 ## oils_failures_allowed: 0
3
4 # forked from spec/ble-idioms
5 # the IFS= eval 'local x' bug
6
7 #### More eval 'local v='
8 case $SH in mksh) exit ;; esac
9
10 set -u
11
12 f() {
13 # The temp env messes it up
14 tmp1= local x=x
15 tmp2= eval 'local y=y'
16
17 # similar to eval
18 tmp3= . $REPO_ROOT/spec/testdata/define-local-var-z.sh
19
20 # Bug does not appear with only eval
21 #eval 'local v=hello'
22
23 #declare -p v
24 echo x=$x
25 echo y=$y
26 echo z=$z
27 }
28
29 f
30
31 ## STDOUT:
32 x=x
33 y=y
34 z=z
35 ## END
36
37 ## N-I mksh STDOUT:
38 ## END
39
40 #### Temp bindings with local
41
42 f() {
43 local x=x
44 tmp='' local tx=tx
45
46 # Hm both y and ty persist in bash/zsh
47 eval 'local y=y'
48 tmp='' eval 'local ty=ty'
49
50 # Why does this have an effect in OSH? Oh because 'unset' is a special
51 # builtin
52 if true; then
53 x='X' unset x
54 tx='TX' unset tx
55 y='Y' unset y
56 ty='TY' unset ty
57 fi
58
59 #unset y
60 #unset ty
61
62 echo x=$x
63 echo tx=$tx
64 echo y=$y
65 echo ty=$ty
66 }
67
68 f
69
70 ## BUG bash/zsh STDOUT:
71 x=x
72 tx=tx
73 y=y
74 ty=ty
75 ## END
76
77 ## STDOUT:
78 x=
79 tx=
80 y=
81 ty=
82 ## END
83
84 #### Temp bindings with unset
85
86 # key point:
87 # unset looks up the stack
88 # local doesn't though
89
90 x=42
91 unset x
92 echo x=$x
93
94 echo ---
95
96 x=42
97 tmp= unset x
98 echo x=$x
99
100 x=42
101 tmp= eval 'unset x'
102 echo x=$x
103
104 echo ---
105
106 shadow() {
107 x=42
108 x=tmp unset x
109 echo x=$x
110
111 x=42
112 x=tmp eval 'unset x'
113 echo x=$x
114 }
115
116 shadow
117
118 echo ---
119
120 case $SH in
121 bash) set -o posix ;;
122 esac
123 shadow
124
125 # Now shadow
126
127 # unset is a special builtin
128 # type unset
129
130 ## STDOUT:
131 x=
132 ---
133 x=
134 x=
135 ---
136 x=42
137 x=42
138 ---
139 x=42
140 x=42
141 ## END
142
143 ## BUG mksh/ash/dash/yash STDOUT:
144 x=
145 ---
146 x=
147 x=
148 ---
149 x=
150 x=
151 ---
152 x=
153 x=
154 ## END