1 ## compare_shells: bash dash mksh zsh ash
2 ## oils_failures_allowed: 3
3
4 # This file relates to:
5 #
6 # - doc/known-differences.md
7 # - "divergence" tag on github:
8 # https://github.com/oils-for-unix/oils/issues?q=is%3Aissue%20state%3Aopen%20label%3Adivergence
9
10 #### xz package: dirprefix="${line##*([}"
11
12 # https://oilshell.zulipchat.com/#narrow/channel/502349-osh/topic/alpine.20xz.20-.20.22.24.7Bline.23.23*.28.5B.7D.22.20interpreted.20as.20extended.20glob/with/519718284
13
14 # NOTE: spec/extglob-match shows that bash respects it
15 #
16 # echo 'strip ##' ${x##@(foo)}
17
18 shopt -s extglob
19
20
21 dirprefix="${line##*([}"
22 echo "-$dirprefix-"
23
24 # Now try with real data
25 line='*([foo'
26 dirprefix="${line##*([}"
27 echo "-$dirprefix-"
28
29 ## STDOUT:
30 --
31 -foo-
32 ## END
33
34 ## N-I mksh/zsh status: 1
35 ## N-I mksh/zsh STDOUT:
36 ## END
37
38 #### !( as negation and subshell versus extended glob - #2463
39
40 have_icu_uc=false
41 have_icu_i18n=false
42
43 if !($have_icu_uc && $have_icu_i18n); then
44 echo one
45 fi
46 echo two
47
48 ## STDOUT:
49 one
50 two
51 ## END
52
53 ## BUG mksh STDOUT:
54 two
55 ## END
56
57 #### Changing PATH will invalidate PATH cache
58
59 mkdir -p _tmp/bin
60 mkdir -p _tmp/bin2
61 printf '#!/usr/bin/env sh\necho hi\n' >_tmp/bin/hello
62 printf '#!/usr/bin/env sh\necho hey\n' >_tmp/bin2/hello
63 chmod +x _tmp/bin/hello
64 chmod +x _tmp/bin2/hello
65
66 BIN=$PWD/_tmp/bin
67 BIN2=$PWD/_tmp/bin2
68
69 # Will find _tmp/bin/hello
70 PATH="$BIN:$PATH" hello
71 echo status=$?
72
73 # Should invalidate cache and then find _tmp/bin2/hello
74 PATH="$BIN2:$PATH" hello
75 echo status=$?
76
77 # Same when PATH= and export PATH=
78 PATH="$BIN:$PATH"
79 hello
80 echo status=$?
81 PATH="$BIN2:$PATH"
82 hello
83 echo status=$?
84
85 export PATH="$BIN:$PATH"
86 hello
87 echo status=$?
88 export PATH="$BIN2:$PATH"
89 hello
90 echo status=$?
91
92 ## STDOUT:
93 hi
94 status=0
95 hey
96 status=0
97 hi
98 status=0
99 hey
100 status=0
101 hi
102 status=0
103 hey
104 status=0
105 ## END
106
107 #### test builtin - Unexpected trailing word '--' (#2409)
108
109 # Minimal repro of sqsh build error
110 set -- -o; test $# -ne 0 -a "$1" != "--"
111 echo status=$?
112
113 # Now hardcode $1
114 test $# -ne 0 -a "-o" != "--"
115 echo status=$?
116
117 # Remove quotes around -o
118 test $# -ne 0 -a -o != "--"
119 echo status=$?
120
121 # How about a different flag?
122 set -- -z; test $# -ne 0 -a "$1" != "--"
123 echo status=$?
124
125 # A non-flag?
126 set -- z; test $# -ne 0 -a "$1" != "--"
127 echo status=$?
128
129 ## STDOUT:
130 status=0
131 status=0
132 status=0
133 status=0
134 status=0
135 ## END
136
137 #### builtin cat crashes a subshell (#2530)
138
139 ((/usr/bin/cat </dev/zero; echo $? >&7) | true) 7>&1
140
141 ((cat </dev/zero; echo $? >&7) | true) 7>&1
142
143 ## STDOUT:
144 141
145 141
146 ## END
147
148 #### test builtin: ( = ) is confusing: equality test or non-empty string test
149
150 # here it's equality
151 test '(' = ')'
152 echo status=$?
153
154 # here it's like -n =
155 test 0 -eq 0 -a '(' = ')'
156 echo status=$?
157
158 ## STDOUT:
159 status=1
160 status=0
161 ## END
162
163 ## BUG zsh STDOUT:
164 status=0
165 status=1
166 ## END
167
168 #### test builtin: ( == ) is confusing: equality test or non-empty string test
169
170 # here it's equality
171 test '(' == ')'
172 echo status=$?
173
174 # here it's like -n ==
175 test 0 -eq 0 -a '(' == ')'
176 echo status=$?
177
178 ## STDOUT:
179 status=1
180 status=0
181 ## END
182
183 ## BUG dash STDOUT:
184 status=0
185 status=0
186 ## END
187
188 ## BUG-2 zsh status: 1
189 ## BUG-2 zsh STDOUT:
190 ## END
191
192 #### Allowed: [[ = ]] and [[ == ]]
193
194 [[ = ]]
195 echo status=$?
196 [[ == ]]
197 echo status=$?
198
199 ## STDOUT:
200 status=0
201 status=0
202 ## END
203
204 ## N-I dash STDOUT:
205 status=127
206 status=127
207 ## END
208
209 ## BUG zsh status: 1
210 ## BUG zsh STDOUT:
211 status=0
212 ## END
213
214 #### Not allowed: [[ ) ]] and [[ ( ]]
215
216 [[ ) ]]
217 echo status=$?
218 [[ ( ]]
219 echo status=$?
220
221 ## status: 2
222 ## OK mksh status: 1
223 ## STDOUT:
224 ## END
225 ## OK zsh status: 1
226 ## OK zsh STDOUT:
227 status=1
228 ## END
229
230 #### [ -f = ] and [ -f == ]
231
232 [ -f = ]
233 echo status=$?
234 [ -f == ]
235 echo status=$?
236
237 ## STDOUT:
238 status=1
239 status=1
240 ## END
241
242 ## BUG zsh status: 1
243 ## BUG zsh STDOUT:
244 status=1
245 ## END
246
247 #### test builtin: ( x ) behavior is the same in both cases
248
249 test '(' x ')'
250 echo status=$?
251
252 test 0 -eq 0 -a '(' x ')'
253 echo status=$?
254
255 ## STDOUT:
256 status=0
257 status=0
258 ## END