1 ## oils_failures_allowed: 0
2 ## compare_shells: dash bash mksh zsh ash
3
4 # TODO mapfile options: -c, -C, -u, etc.
5
6 #### echo dashes
7 echo -
8 echo --
9 echo ---
10 ## STDOUT:
11 -
12 --
13 ---
14 ## END
15 ## BUG zsh STDOUT:
16
17 --
18 ---
19 ## END
20
21 #### echo backslashes
22 echo \\
23 echo '\'
24 echo '\\'
25 echo "\\"
26 ## STDOUT:
27 \
28 \
29 \\
30 \
31 ## BUG dash/mksh/zsh STDOUT:
32 \
33 \
34 \
35 \
36 ## END
37
38 #### echo -e backslashes
39 echo -e \\
40 echo -e '\'
41 echo -e '\\'
42 echo -e "\\"
43 echo
44
45 # backslash at end of line
46 echo -e '\
47 line2'
48 ## STDOUT:
49 \
50 \
51 \
52 \
53
54 \
55 line2
56 ## N-I dash STDOUT:
57 -e \
58 -e \
59 -e \
60 -e \
61
62 -e \
63 line2
64 ## END
65
66 #### echo builtin should disallow typed args - literal
67 echo (42)
68 ## status: 2
69 ## OK mksh/zsh status: 1
70 ## STDOUT:
71 ## END
72
73 #### echo builtin should disallow typed args - variable
74 var x = 43
75 echo (x)
76 ## status: 2
77 ## OK mksh/zsh status: 1
78 ## STDOUT:
79 ## END
80
81 #### echo -en
82 echo -en 'abc\ndef\n'
83 ## STDOUT:
84 abc
85 def
86 ## END
87 ## N-I dash STDOUT:
88 -en abc
89 def
90
91 ## END
92
93 #### echo -ez (invalid flag)
94 # bash differs from the other three shells, but its behavior is possibly more
95 # sensible, if you're going to ignore the error. It doesn't make sense for
96 # the 'e' to mean 2 different things simultaneously: flag and literal to be
97 # printed.
98 echo -ez 'abc\n'
99 ## STDOUT:
100 -ez abc\n
101 ## END
102 ## OK dash/mksh/zsh STDOUT:
103 -ez abc
104
105 ## END
106
107 #### echo -e with embedded newline
108 flags='-e'
109 case $SH in dash) flags='' ;; esac
110
111 echo $flags 'foo
112 bar'
113 ## STDOUT:
114 foo
115 bar
116 ## END
117
118 #### echo -e line continuation
119 flags='-e'
120 case $SH in dash) flags='' ;; esac
121
122 echo $flags 'foo\
123 bar'
124 ## STDOUT:
125 foo\
126 bar
127 ## END
128
129 #### echo -e with C escapes
130 # https://www.gnu.org/software/bash/manual/bashref.html#Bourne-Shell-Builtins
131 # not sure why \c is like NUL?
132 # zsh doesn't allow \E for some reason.
133 echo -e '\a\b\d\e\f'
134 ## stdout-json: "\u0007\u0008\\d\u001b\u000c\n"
135 ## N-I dash stdout-json: "-e \u0007\u0008\\d\\e\u000c\n"
136
137 #### echo -e with whitespace C escapes
138 echo -e '\n\r\t\v'
139 ## stdout-json: "\n\r\t\u000b\n"
140 ## N-I dash stdout-json: "-e \n\r\t\u000b\n"
141
142 #### \0
143 echo -e 'ab\0cd'
144 ## stdout-json: "ab\u0000cd\n"
145 ## N-I dash stdout-json: "-e ab\u0000cd\n"
146
147 #### \c stops processing input
148 flags='-e'
149 case $SH in dash) flags='' ;; esac
150
151 echo $flags xy 'ab\cde' 'zzz'
152 ## stdout-json: "xy ab"
153 ## N-I mksh stdout-json: "xy abde zzz"
154
155 #### echo -e with hex escape
156 echo -e 'abcd\x65f'
157 ## STDOUT:
158 abcdef
159 ## END
160 ## N-I dash STDOUT:
161 -e abcd\x65f
162 ## END
163
164 #### echo -e with octal escape
165 flags='-e'
166 case $SH in dash) flags='' ;; esac
167
168 echo $flags 'abcd\044e'
169 ## STDOUT:
170 abcd$e
171 ## END
172
173 #### echo -e with 4 digit unicode escape
174 flags='-e'
175 case $SH in dash) flags='' ;; esac
176
177 echo $flags 'abcd\u0065f'
178 ## STDOUT:
179 abcdef
180 ## END
181 ## N-I dash/ash STDOUT:
182 abcd\u0065f
183 ## END
184
185 #### echo -e with 8 digit unicode escape
186 flags='-e'
187 case $SH in dash) flags='' ;; esac
188
189 echo $flags 'abcd\U00000065f'
190 ## STDOUT:
191 abcdef
192 ## END
193 ## N-I dash/ash STDOUT:
194 abcd\U00000065f
195 ## END
196
197 #### \0377 is the highest octal byte
198 echo -en '\03777' | od -A n -t x1 | sed 's/ \+/ /g'
199 ## STDOUT:
200 ff 37
201 ## END
202 ## N-I dash STDOUT:
203 2d 65 6e 20 ff 37 0a
204 ## END
205
206 #### \0400 is one more than the highest octal byte
207 # It is 256 % 256 which gets interpreted as a NUL byte.
208 echo -en '\04000' | od -A n -t x1 | sed 's/ \+/ /g'
209 ## STDOUT:
210 00 30
211 ## END
212 ## BUG ash STDOUT:
213 20 30 30
214 ## END
215 ## N-I dash STDOUT:
216 2d 65 6e 20 00 30 0a
217 ## END
218
219 #### \0777 is out of range
220 flags='-en'
221 case $SH in dash) flags='-n' ;; esac
222
223 echo $flags '\0777' | od -A n -t x1 | sed 's/ \+/ /g'
224 ## STDOUT:
225 ff
226 ## END
227 ## BUG mksh STDOUT:
228 c3 bf
229 ## END
230 ## BUG ash STDOUT:
231 3f 37
232 ## END
233
234 #### incomplete hex escape
235 echo -en 'abcd\x6' | od -A n -c | sed 's/ \+/ /g'
236 ## STDOUT:
237 a b c d 006
238 ## END
239 ## N-I dash STDOUT:
240 - e n a b c d \ x 6 \n
241 ## END
242
243 #### \x
244 # I consider mksh and zsh a bug because \x is not an escape
245 echo -e '\x' '\xg' | od -A n -c | sed 's/ \+/ /g'
246 ## STDOUT:
247 \ x \ x g \n
248 ## END
249 ## N-I dash STDOUT:
250 - e \ x \ x g \n
251 ## END
252 ## BUG mksh/zsh STDOUT:
253 \0 \0 g \n
254 ## END
255
256 #### incomplete octal escape
257 flags='-en'
258 case $SH in dash) flags='-n' ;; esac
259
260 echo $flags 'abcd\04' | od -A n -c | sed 's/ \+/ /g'
261 ## STDOUT:
262 a b c d 004
263 ## END
264
265 #### incomplete unicode escape
266 echo -en 'abcd\u006' | od -A n -c | sed 's/ \+/ /g'
267 ## STDOUT:
268 a b c d 006
269 ## END
270 ## N-I dash STDOUT:
271 - e n a b c d \ u 0 0 6 \n
272 ## END
273 ## BUG ash STDOUT:
274 a b c d \ u 0 0 6
275 ## END
276
277 #### \u6
278 flags='-en'
279 case $SH in dash) flags='-n' ;; esac
280
281 echo $flags '\u6' | od -A n -c | sed 's/ \+/ /g'
282 ## STDOUT:
283 006
284 ## END
285 ## N-I dash/ash STDOUT:
286 \ u 6
287 ## END
288
289 #### \0 \1 \8
290 # \0 is special, but \1 isn't in bash
291 # \1 is special in dash! geez
292 flags='-en'
293 case $SH in dash) flags='-n' ;; esac
294
295 echo $flags '\0' '\1' '\8' | od -A n -c | sed 's/ \+/ /g'
296 ## STDOUT:
297 \0 \ 1 \ 8
298 ## END
299 ## BUG dash/ash STDOUT:
300 \0 001 \ 8
301 ## END
302
303
304 #### echo to redirected directory is an error
305 mkdir -p dir
306
307 echo foo > ./dir
308 echo status=$?
309 printf foo > ./dir
310 echo status=$?
311
312 ## STDOUT:
313 status=1
314 status=1
315 ## END
316 ## OK dash STDOUT:
317 status=2
318 status=2
319 ## END
320