1 |
## oils_failures_allowed: 2
|
2 |
## compare_shells: dash bash mksh zsh ash
|
3 |
|
4 |
|
5 |
# echo, read, mapfile
|
6 |
# TODO mapfile options: -c, -C, -u, etc.
|
7 |
|
8 |
|
9 |
echo -
|
10 |
echo --
|
11 |
echo ---
|
12 |
## stdout-json: "-\n--\n---\n"
|
13 |
## BUG zsh stdout-json: "\n--\n---\n"
|
14 |
|
15 |
|
16 |
echo \\
|
17 |
echo '\'
|
18 |
echo '\\'
|
19 |
echo "\\"
|
20 |
## STDOUT:
|
21 |
\
|
22 |
\
|
23 |
\\
|
24 |
\
|
25 |
## BUG dash/mksh/zsh STDOUT:
|
26 |
\
|
27 |
\
|
28 |
\
|
29 |
\
|
30 |
## END
|
31 |
|
32 |
|
33 |
echo -e \\
|
34 |
echo -e '\'
|
35 |
echo -e '\\'
|
36 |
echo -e "\\"
|
37 |
## STDOUT:
|
38 |
\
|
39 |
\
|
40 |
\
|
41 |
\
|
42 |
## N-I dash STDOUT:
|
43 |
-e \
|
44 |
-e \
|
45 |
-e \
|
46 |
-e \
|
47 |
## END
|
48 |
|
49 |
|
50 |
echo (42)
|
51 |
## status: 2
|
52 |
## OK mksh/zsh status: 1
|
53 |
## STDOUT:
|
54 |
## END
|
55 |
|
56 |
|
57 |
var x = 43
|
58 |
echo (x)
|
59 |
## status: 2
|
60 |
## OK mksh/zsh status: 1
|
61 |
## STDOUT:
|
62 |
## END
|
63 |
|
64 |
|
65 |
echo -en 'abc\ndef\n'
|
66 |
## stdout-json: "abc\ndef\n"
|
67 |
## N-I dash stdout-json: "-en abc\ndef\n\n"
|
68 |
|
69 |
|
70 |
# bash differs from the other three shells, but its behavior is possibly more
|
71 |
# sensible, if you're going to ignore the error. It doesn't make sense for
|
72 |
# the 'e' to mean 2 different things simultaneously: flag and literal to be
|
73 |
# printed.
|
74 |
echo -ez 'abc\n'
|
75 |
## stdout-json: "-ez abc\\n\n"
|
76 |
## OK dash/mksh/zsh stdout-json: "-ez abc\n\n"
|
77 |
|
78 |
|
79 |
flags='-e'
|
80 |
case $SH in dash) flags='' ;; esac
|
81 |
|
82 |
echo $flags 'foo
|
83 |
bar'
|
84 |
## STDOUT:
|
85 |
foo
|
86 |
bar
|
87 |
## END
|
88 |
|
89 |
|
90 |
flags='-e'
|
91 |
case $SH in dash) flags='' ;; esac
|
92 |
|
93 |
echo $flags 'foo\
|
94 |
bar'
|
95 |
## STDOUT:
|
96 |
foo\
|
97 |
bar
|
98 |
## END
|
99 |
|
100 |
|
101 |
# https://www.gnu.org/software/bash/manual/bashref.html#Bourne-Shell-Builtins
|
102 |
# not sure why \c is like NUL?
|
103 |
# zsh doesn't allow \E for some reason.
|
104 |
echo -e '\a\b\d\e\f'
|
105 |
## stdout-json: "\u0007\u0008\\d\u001b\u000c\n"
|
106 |
## N-I dash stdout-json: "-e \u0007\u0008\\d\\e\u000c\n"
|
107 |
|
108 |
|
109 |
echo -e '\n\r\t\v'
|
110 |
## stdout-json: "\n\r\t\u000b\n"
|
111 |
## N-I dash stdout-json: "-e \n\r\t\u000b\n"
|
112 |
|
113 |
|
114 |
echo -e 'ab\0cd'
|
115 |
## stdout-json: "ab\u0000cd\n"
|
116 |
## N-I dash stdout-json: "-e ab\u0000cd\n"
|
117 |
|
118 |
|
119 |
flags='-e'
|
120 |
case $SH in dash) flags='' ;; esac
|
121 |
|
122 |
echo $flags xy 'ab\cde' 'zzz'
|
123 |
## stdout-json: "xy ab"
|
124 |
## N-I mksh stdout-json: "xy abde zzz"
|
125 |
|
126 |
|
127 |
echo -e 'abcd\x65f'
|
128 |
## stdout-json: "abcdef\n"
|
129 |
## N-I dash stdout-json: "-e abcd\\x65f\n"
|
130 |
|
131 |
|
132 |
flags='-e'
|
133 |
case $SH in dash) flags='' ;; esac
|
134 |
|
135 |
echo $flags 'abcd\044e'
|
136 |
## stdout-json: "abcd$e\n"
|
137 |
|
138 |
|
139 |
flags='-e'
|
140 |
case $SH in dash) flags='' ;; esac
|
141 |
|
142 |
echo $flags 'abcd\u0065f'
|
143 |
## STDOUT:
|
144 |
abcdef
|
145 |
## END
|
146 |
## N-I dash/ash stdout-json: "abcd\\u0065f\n"
|
147 |
|
148 |
|
149 |
flags='-e'
|
150 |
case $SH in dash) flags='' ;; esac
|
151 |
|
152 |
echo $flags 'abcd\U00000065f'
|
153 |
## STDOUT:
|
154 |
abcdef
|
155 |
## END
|
156 |
## N-I dash/ash stdout-json: "abcd\\U00000065f\n"
|
157 |
|
158 |
|
159 |
echo -en '\03777' | od -A n -t x1 | sed 's/ \+/ /g'
|
160 |
## stdout-json: " ff 37\n"
|
161 |
## N-I dash stdout-json: " 2d 65 6e 20 ff 37 0a\n"
|
162 |
|
163 |
|
164 |
# It is 256 % 256 which gets interpreted as a NUL byte.
|
165 |
echo -en '\04000' | od -A n -t x1 | sed 's/ \+/ /g'
|
166 |
## stdout-json: " 00 30\n"
|
167 |
## BUG ash stdout-json: " 20 30 30\n"
|
168 |
## N-I dash stdout-json: " 2d 65 6e 20 00 30 0a\n"
|
169 |
|
170 |
|
171 |
flags='-en'
|
172 |
case $SH in dash) flags='-n' ;; esac
|
173 |
|
174 |
echo $flags '\0777' | od -A n -t x1 | sed 's/ \+/ /g'
|
175 |
## stdout-json: " ff\n"
|
176 |
## BUG mksh stdout-json: " c3 bf\n"
|
177 |
## BUG ash stdout-json: " 3f 37\n"
|
178 |
|
179 |
|
180 |
echo -en 'abcd\x6' | od -A n -c | sed 's/ \+/ /g'
|
181 |
## stdout-json: " a b c d 006\n"
|
182 |
## N-I dash stdout-json: " - e n a b c d \\ x 6 \\n\n"
|
183 |
|
184 |
|
185 |
# I consider mksh and zsh a bug because \x is not an escape
|
186 |
echo -e '\x' '\xg' | od -A n -c | sed 's/ \+/ /g'
|
187 |
## stdout-json: " \\ x \\ x g \\n\n"
|
188 |
## N-I dash stdout-json: " - e \\ x \\ x g \\n\n"
|
189 |
## BUG mksh/zsh stdout-json: " \\0 \\0 g \\n\n"
|
190 |
|
191 |
|
192 |
flags='-en'
|
193 |
case $SH in dash) flags='-n' ;; esac
|
194 |
|
195 |
echo $flags 'abcd\04' | od -A n -c | sed 's/ \+/ /g'
|
196 |
## stdout-json: " a b c d 004\n"
|
197 |
|
198 |
|
199 |
echo -en 'abcd\u006' | od -A n -c | sed 's/ \+/ /g'
|
200 |
## stdout-json: " a b c d 006\n"
|
201 |
## N-I dash stdout-json: " - e n a b c d \\ u 0 0 6 \\n\n"
|
202 |
## BUG ash stdout-json: " a b c d \\ u 0 0 6\n"
|
203 |
|
204 |
|
205 |
flags='-en'
|
206 |
case $SH in dash) flags='-n' ;; esac
|
207 |
|
208 |
echo $flags '\u6' | od -A n -c | sed 's/ \+/ /g'
|
209 |
## stdout-json: " 006\n"
|
210 |
## N-I dash/ash stdout-json: " \\ u 6\n"
|
211 |
|
212 |
|
213 |
# \0 is special, but \1 isn't in bash
|
214 |
# \1 is special in dash! geez
|
215 |
flags='-en'
|
216 |
case $SH in dash) flags='-n' ;; esac
|
217 |
|
218 |
echo $flags '\0' '\1' '\8' | od -A n -c | sed 's/ \+/ /g'
|
219 |
## stdout-json: " \\0 \\ 1 \\ 8\n"
|
220 |
## BUG dash/ash stdout-json: " \\0 001 \\ 8\n"
|
221 |
|
222 |
|
223 |
# NOTE: there are TABS below
|
224 |
read x <<EOF
|
225 |
A B C D E
|
226 |
FG
|
227 |
EOF
|
228 |
echo "[$x]"
|
229 |
## stdout: [A B C D E]
|
230 |
## status: 0
|
231 |
|
232 |
|
233 |
echo -n '' > $TMP/empty.txt
|
234 |
read x < $TMP/empty.txt
|
235 |
argv.py "status=$?" "$x"
|
236 |
|
237 |
# No variable name, behaves the same
|
238 |
read < $TMP/empty.txt
|
239 |
argv.py "status=$?" "$REPLY"
|
240 |
|
241 |
## STDOUT:
|
242 |
['status=1', '']
|
243 |
['status=1', '']
|
244 |
## END
|
245 |
## OK dash STDOUT:
|
246 |
['status=1', '']
|
247 |
['status=2', '']
|
248 |
## END
|
249 |
## status: 0
|
250 |
|
251 |
|
252 |
read -n 1 </dev/null
|
253 |
echo $?
|
254 |
## STDOUT:
|
255 |
1
|
256 |
## END
|
257 |
## OK dash stdout: 2
|
258 |
|
259 |
|
260 |
echo | read
|
261 |
echo status=$?
|
262 |
## STDOUT:
|
263 |
status=0
|
264 |
## END
|
265 |
## BUG dash STDOUT:
|
266 |
status=2
|
267 |
## END
|
268 |
|
269 |
|
270 |
# This is odd because the variable is populated successfully. OSH/Oil might
|
271 |
# need a separate put reading feature that doesn't use IFS.
|
272 |
echo -n ZZZ | { read x; echo $?; echo $x; }
|
273 |
## stdout-json: "1\nZZZ\n"
|
274 |
## status: 0
|
275 |
|
276 |
|
277 |
# NOTE: there are TABS below
|
278 |
read x y z <<EOF
|
279 |
A B C D E
|
280 |
FG
|
281 |
EOF
|
282 |
echo "[$x/$y/$z]"
|
283 |
## stdout: [A/B/C D E]
|
284 |
## status: 0
|
285 |
|
286 |
|
287 |
set -o errexit
|
288 |
set -o nounset # hm this doesn't change it
|
289 |
read x y z <<EOF
|
290 |
A B
|
291 |
EOF
|
292 |
echo /$x/$y/$z/
|
293 |
## stdout: /A/B//
|
294 |
## status: 0
|
295 |
|
296 |
|
297 |
echo 12345 > $TMP/readn.txt
|
298 |
read -n 4 x < $TMP/readn.txt
|
299 |
read -n 2 < $TMP/readn.txt # Do it again with no variable
|
300 |
argv.py $x $REPLY
|
301 |
## stdout: ['1234', '12']
|
302 |
## N-I dash/zsh stdout: []
|
303 |
|
304 |
|
305 |
echo XYZ > "$TMP/readn.txt"
|
306 |
IFS= TMOUT= read -n 1 char < "$TMP/readn.txt"
|
307 |
argv.py "$char"
|
308 |
## stdout: ['X']
|
309 |
## N-I dash/zsh stdout: ['']
|
310 |
|
311 |
|
312 |
read -n not_a_number
|
313 |
echo status=$?
|
314 |
## stdout: status=2
|
315 |
## OK bash stdout: status=1
|
316 |
## N-I zsh stdout-json: ""
|
317 |
|
318 |
|
319 |
case $SH in (dash|ash|zsh) exit ;; esac
|
320 |
|
321 |
echo abcxyz | { read -n 3; echo reply=$REPLY; }
|
322 |
## status: 0
|
323 |
## stdout: reply=abc
|
324 |
## N-I dash/ash/zsh stdout-json: ""
|
325 |
|
326 |
# zsh appears to hang with -k
|
327 |
## N-I zsh stdout-json: ""
|
328 |
|
329 |
|
330 |
echo 123 > $TMP/readreply.txt
|
331 |
read < $TMP/readreply.txt
|
332 |
echo $REPLY
|
333 |
## stdout: 123
|
334 |
## N-I dash stdout:
|
335 |
|
336 |
|
337 |
# dash, ash and zsh do not implement read -N
|
338 |
# mksh treats -N exactly the same as -n
|
339 |
case $SH in (dash|ash|zsh) exit ;; esac
|
340 |
|
341 |
# bash docs: https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html
|
342 |
|
343 |
echo 'a b c' > $TMP/readn.txt
|
344 |
|
345 |
echo 'read -n'
|
346 |
read -n 5 A B C < $TMP/readn.txt; echo "'$A' '$B' '$C'"
|
347 |
read -n 4 A B C < $TMP/readn.txt; echo "'$A' '$B' '$C'"
|
348 |
echo
|
349 |
|
350 |
echo 'read -N'
|
351 |
read -N 5 A B C < $TMP/readn.txt; echo "'$A' '$B' '$C'"
|
352 |
read -N 4 A B C < $TMP/readn.txt; echo "'$A' '$B' '$C'"
|
353 |
## STDOUT:
|
354 |
read -n
|
355 |
'a' 'b' 'c'
|
356 |
'a' 'b' ''
|
357 |
|
358 |
read -N
|
359 |
'a b c' '' ''
|
360 |
'a b ' '' ''
|
361 |
## END
|
362 |
## N-I dash/ash/zsh stdout-json: ""
|
363 |
## BUG mksh STDOUT:
|
364 |
read -n
|
365 |
'a' 'b' 'c'
|
366 |
'a' 'b' ''
|
367 |
|
368 |
read -N
|
369 |
'a' 'b' 'c'
|
370 |
'a' 'b' ''
|
371 |
## END
|
372 |
|
373 |
|
374 |
case $SH in (dash|ash|zsh) exit ;; esac
|
375 |
|
376 |
echo $'a\nb\nc' > $TMP/read-lines.txt
|
377 |
|
378 |
read -N 3 out < $TMP/read-lines.txt
|
379 |
echo "$out"
|
380 |
## STDOUT:
|
381 |
a
|
382 |
b
|
383 |
## END
|
384 |
## N-I dash/ash/zsh stdout-json: ""
|
385 |
|
386 |
|
387 |
|
388 |
echo 'a b' > $TMP/read-few.txt
|
389 |
|
390 |
c='some value'
|
391 |
read a b c < $TMP/read-few.txt
|
392 |
echo "'$a' '$b' '$c'"
|
393 |
|
394 |
case $SH in (dash) exit ;; esac # dash does not implement -n
|
395 |
|
396 |
c='some value'
|
397 |
read -n 3 a b c < $TMP/read-few.txt
|
398 |
echo "'$a' '$b' '$c'"
|
399 |
## STDOUT:
|
400 |
'a' 'b' ''
|
401 |
'a' 'b' ''
|
402 |
## END
|
403 |
## N-I dash STDOUT:
|
404 |
'a' 'b' ''
|
405 |
## END
|
406 |
## BUG zsh STDOUT:
|
407 |
'a' 'b' ''
|
408 |
'b' '' ''
|
409 |
## END
|
410 |
|
411 |
|
412 |
echo 'one\ two' > $TMP/readr.txt
|
413 |
read escaped < $TMP/readr.txt
|
414 |
read -r raw < $TMP/readr.txt
|
415 |
argv.py "$escaped" "$raw"
|
416 |
## stdout: ['one two', 'one\\ two']
|
417 |
|
418 |
|
419 |
echo 'one\ two\x65three' > $TMP/readr.txt
|
420 |
read escaped < $TMP/readr.txt
|
421 |
read -r raw < $TMP/readr.txt
|
422 |
argv.py "$escaped" "$raw"
|
423 |
# mksh respects the hex escapes here, but other shells don't!
|
424 |
## stdout: ['one twox65three', 'one\\ two\\x65three']
|
425 |
## BUG mksh/zsh stdout: ['one twoethree', 'one\\ twoethree']
|
426 |
|
427 |
|
428 |
# NOTE: osh failing because of file descriptor issue. stdin has to be closed!
|
429 |
tmp=$TMP/$(basename $SH)-readr.txt
|
430 |
echo -e 'one\\\ntwo\n' > $tmp
|
431 |
read escaped < $tmp
|
432 |
read -r raw < $tmp
|
433 |
argv.py "$escaped" "$raw"
|
434 |
## stdout: ['onetwo', 'one\\']
|
435 |
## N-I dash stdout: ['-e onetwo', '-e one\\']
|
436 |
|
437 |
|
438 |
read x y << 'EOF'
|
439 |
one-\
|
440 |
two three-\
|
441 |
four five-\
|
442 |
six
|
443 |
EOF
|
444 |
argv.py "$x" "$y" "$z"
|
445 |
## stdout: ['one-two', 'three-four five-six', '']
|
446 |
|
447 |
|
448 |
echo '\nline' > $TMP/readr.txt
|
449 |
read escaped < $TMP/readr.txt
|
450 |
read -r raw < $TMP/readr.txt
|
451 |
argv.py "$escaped" "$raw"
|
452 |
# dash/mksh/zsh are bugs because at least the raw mode should let you read a
|
453 |
# literal \n.
|
454 |
## stdout: ['nline', '\\nline']
|
455 |
## BUG dash/mksh/zsh stdout: ['', '']
|
456 |
|
457 |
|
458 |
case $SH in (dash|zsh) exit ;; esac
|
459 |
|
460 |
# It's hard to really test this because it requires a terminal. We hit a
|
461 |
# different code path when reading through a pipe. There can be bugs there
|
462 |
# too!
|
463 |
|
464 |
echo foo | { read -s; echo $REPLY; }
|
465 |
echo bar | { read -n 2 -s; echo $REPLY; }
|
466 |
|
467 |
# Hm no exit 1 here? Weird
|
468 |
echo b | { read -n 2 -s; echo $?; echo $REPLY; }
|
469 |
## STDOUT:
|
470 |
foo
|
471 |
ba
|
472 |
0
|
473 |
b
|
474 |
## END
|
475 |
## N-I dash/zsh stdout-json: ""
|
476 |
|
477 |
|
478 |
# The leading spaces are stripped if they appear in IFS.
|
479 |
IFS=$(echo -e '\n')
|
480 |
read var <<EOF
|
481 |
a b c
|
482 |
d e f
|
483 |
EOF
|
484 |
echo "[$var]"
|
485 |
## stdout: [ a b c]
|
486 |
## N-I dash stdout: [a b c]
|
487 |
|
488 |
|
489 |
# The leading spaces are stripped if they appear in IFS.
|
490 |
# IFS chars are escaped with :.
|
491 |
tmp=$TMP/$(basename $SH)-read-ifs.txt
|
492 |
IFS=:
|
493 |
cat >$tmp <<'EOF'
|
494 |
\\a :b\: c:d\
|
495 |
e
|
496 |
EOF
|
497 |
read a b c d < $tmp
|
498 |
# Use printf because echo in dash/mksh interprets escapes, while it doesn't in
|
499 |
# bash.
|
500 |
printf "%s\n" "[$a|$b|$c|$d]"
|
501 |
## stdout: [ \a |b: c|d e|]
|
502 |
|
503 |
|
504 |
IFS=''
|
505 |
read x y <<EOF
|
506 |
a b c d
|
507 |
EOF
|
508 |
echo "[$x|$y]"
|
509 |
## stdout: [ a b c d|]
|
510 |
|
511 |
|
512 |
# bash doesn't respect these, but other shells do. Gah! I think bash
|
513 |
# behavior makes more sense. It only escapes IFS.
|
514 |
echo '\a \b \c \d \e \f \g \h \x65 \145 \i' > $TMP/read-c.txt
|
515 |
read line < $TMP/read-c.txt
|
516 |
echo $line
|
517 |
## stdout-json: "a b c d e f g h x65 145 i\n"
|
518 |
## BUG ash stdout-json: "abcdefghx65 145 i\n"
|
519 |
## BUG dash/zsh stdout-json: "\u0007 \u0008\n"
|
520 |
## BUG mksh stdout-json: "\u0007 \u0008 d \u001b \u000c g h e 145 i\n"
|
521 |
|
522 |
|
523 |
f() {
|
524 |
read head << EOF
|
525 |
ref: refs/heads/dev/andy
|
526 |
EOF
|
527 |
}
|
528 |
f
|
529 |
echo $head
|
530 |
## STDOUT:
|
531 |
ref: refs/heads/dev/andy
|
532 |
## END
|
533 |
|
534 |
|
535 |
|
536 |
# read -a is used in bash-completion
|
537 |
# none of these shells implement it
|
538 |
case $SH in
|
539 |
*mksh|*dash|*zsh|*/ash)
|
540 |
exit 2;
|
541 |
;;
|
542 |
esac
|
543 |
|
544 |
read -a myarray <<'EOF'
|
545 |
a b c\ d
|
546 |
EOF
|
547 |
argv.py "${myarray[@]}"
|
548 |
|
549 |
# arguments are ignored here
|
550 |
read -r -a array2 extra arguments <<'EOF'
|
551 |
a b c\ d
|
552 |
EOF
|
553 |
argv.py "${array2[@]}"
|
554 |
argv.py "${extra[@]}"
|
555 |
argv.py "${arguments[@]}"
|
556 |
## status: 0
|
557 |
## STDOUT:
|
558 |
['a', 'b', 'c d']
|
559 |
['a', 'b', 'c\\', 'd']
|
560 |
[]
|
561 |
[]
|
562 |
## END
|
563 |
## N-I dash/mksh/zsh/ash status: 2
|
564 |
## N-I dash/mksh/zsh/ash stdout-json: ""
|
565 |
|
566 |
|
567 |
printf a,b,c:d,e,f:g,h,i | {
|
568 |
IFS=,
|
569 |
read -d : v1
|
570 |
echo "v1=$v1"
|
571 |
read -d : v1 v2
|
572 |
echo "v1=$v1 v2=$v2"
|
573 |
read -d : v1 v2 v3
|
574 |
echo "v1=$v1 v2=$v2 v3=$v3"
|
575 |
}
|
576 |
## STDOUT:
|
577 |
v1=a,b,c
|
578 |
v1=d v2=e,f
|
579 |
v1=g v2=h v3=i
|
580 |
## END
|
581 |
## N-I dash STDOUT:
|
582 |
v1=
|
583 |
v1= v2=
|
584 |
v1= v2= v3=
|
585 |
## END
|
586 |
|
587 |
|
588 |
printf 'a,b,c\0d,e,f\0g,h,i' | {
|
589 |
IFS=,
|
590 |
read -d '' v1
|
591 |
echo "v1=$v1"
|
592 |
read -d '' v1 v2
|
593 |
echo "v1=$v1 v2=$v2"
|
594 |
read -d '' v1 v2 v3
|
595 |
echo "v1=$v1 v2=$v2 v3=$v3"
|
596 |
}
|
597 |
## STDOUT:
|
598 |
v1=a,b,c
|
599 |
v1=d v2=e,f
|
600 |
v1=g v2=h v3=i
|
601 |
## END
|
602 |
## N-I dash STDOUT:
|
603 |
v1=
|
604 |
v1= v2=
|
605 |
v1= v2= v3=
|
606 |
## END
|
607 |
|
608 |
|
609 |
read -rd '' var <<EOF
|
610 |
foo
|
611 |
bar
|
612 |
EOF
|
613 |
echo "$var"
|
614 |
## STDOUT:
|
615 |
foo
|
616 |
bar
|
617 |
## END
|
618 |
## N-I dash stdout-json: "\n"
|
619 |
|
620 |
|
621 |
{ read -d : part
|
622 |
echo $part $?
|
623 |
read -d : part
|
624 |
echo $part $?
|
625 |
} <<EOF
|
626 |
foo:bar
|
627 |
EOF
|
628 |
## STDOUT:
|
629 |
foo 0
|
630 |
bar 1
|
631 |
## END
|
632 |
## N-I dash STDOUT:
|
633 |
2
|
634 |
2
|
635 |
## END
|
636 |
|
637 |
|
638 |
case $SH in (dash|zsh|mksh) exit ;; esac
|
639 |
|
640 |
# is there input available?
|
641 |
read -t 0 < /dev/null
|
642 |
echo $?
|
643 |
|
644 |
# floating point
|
645 |
read -t 0.0 < /dev/null
|
646 |
echo $?
|
647 |
|
648 |
# floating point
|
649 |
echo foo | { read -t 0; echo reply=$REPLY; }
|
650 |
echo $?
|
651 |
|
652 |
## STDOUT:
|
653 |
0
|
654 |
0
|
655 |
reply=
|
656 |
0
|
657 |
## END
|
658 |
## N-I dash/zsh/mksh stdout-json: ""
|
659 |
|
660 |
|
661 |
case $SH in (dash) exit ;; esac
|
662 |
|
663 |
read -t 0.5 < /dev/null
|
664 |
echo $?
|
665 |
|
666 |
## STDOUT:
|
667 |
1
|
668 |
## END
|
669 |
## BUG zsh/mksh STDOUT:
|
670 |
1
|
671 |
## END
|
672 |
## N-I dash stdout-json: ""
|
673 |
|
674 |
|
675 |
# bash appears to just take the absolute value?
|
676 |
|
677 |
read -t -0.5 < /dev/null
|
678 |
echo $?
|
679 |
|
680 |
## STDOUT:
|
681 |
2
|
682 |
## END
|
683 |
## BUG bash STDOUT:
|
684 |
1
|
685 |
## END
|
686 |
## BUG zsh stdout-json: ""
|
687 |
## BUG zsh status: 1
|
688 |
|
689 |
|
690 |
case $SH in (dash|mksh) exit ;; esac
|
691 |
|
692 |
# file descriptor
|
693 |
read -u 3 3<<EOF
|
694 |
hi
|
695 |
EOF
|
696 |
echo reply=$REPLY
|
697 |
## STDOUT:
|
698 |
reply=hi
|
699 |
## END
|
700 |
## N-I dash/mksh stdout-json: ""
|
701 |
|
702 |
|
703 |
read -u -3
|
704 |
echo status=$?
|
705 |
## STDOUT:
|
706 |
status=2
|
707 |
## END
|
708 |
## OK bash/zsh STDOUT:
|
709 |
status=1
|
710 |
## END
|
711 |
|
712 |
|
713 |
case $SH in (dash|zsh|ash) exit ;; esac
|
714 |
|
715 |
echo foobar | { read -n 5 -d b; echo $REPLY; }
|
716 |
echo foobar | { read -N 5 -d b; echo $REPLY; }
|
717 |
## STDOUT:
|
718 |
foo
|
719 |
fooba
|
720 |
## END
|
721 |
## OK mksh STDOUT:
|
722 |
fooba
|
723 |
fooba
|
724 |
## END
|
725 |
## N-I dash/zsh/ash stdout-json: ""
|
726 |
|
727 |
|
728 |
|
729 |
# hm DISABLED if we're not going to the terminal
|
730 |
# so we're only testing that it accepts the flag here
|
731 |
|
732 |
case $SH in (dash|mksh|zsh) exit ;; esac
|
733 |
|
734 |
echo hi | { read -p 'P'; echo $REPLY; }
|
735 |
echo hi | { read -p 'P' -n 1; echo $REPLY; }
|
736 |
## STDOUT:
|
737 |
hi
|
738 |
h
|
739 |
## END
|
740 |
## stderr-json: ""
|
741 |
## N-I dash/mksh/zsh stdout-json: ""
|
742 |
|
743 |
|
744 |
read -n -1
|
745 |
echo status=$?
|
746 |
## STDOUT:
|
747 |
status=2
|
748 |
## END
|
749 |
## OK bash stdout: status=1
|
750 |
## BUG mksh stdout-json: ""
|
751 |
# zsh gives a fatal error? seems inconsistent
|
752 |
## BUG zsh stdout-json: ""
|
753 |
## BUG zsh status: 1
|
754 |
|
755 |
|
756 |
echo hi | { read -rn1 var; echo var=$var; }
|
757 |
## STDOUT:
|
758 |
var=h
|
759 |
## END
|
760 |
## N-I dash/zsh STDOUT:
|
761 |
var=
|
762 |
## END
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
case $SH in (dash|zsh|mksh) exit ;; esac # NOT IMPLEMENTED
|
768 |
|
769 |
mkdir -p read0
|
770 |
cd read0
|
771 |
rm -f *
|
772 |
|
773 |
touch a\\b\\c\\d # -r is necessary!
|
774 |
|
775 |
find . -type f -a -print0 | { read -r -d ''; echo "[$REPLY]"; }
|
776 |
|
777 |
## STDOUT:
|
778 |
[./a\b\c\d]
|
779 |
## END
|
780 |
## N-I dash/zsh/mksh STDOUT:
|
781 |
## END
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
# This tickles an infinite loop bug in our version of mksh! TODO: upgrade the
|
787 |
# version and enable this
|
788 |
case $SH in (mksh) return ;; esac
|
789 |
|
790 |
cd $TMP
|
791 |
mkdir -p dir
|
792 |
read x < ./dir
|
793 |
echo status=$?
|
794 |
|
795 |
## STDOUT:
|
796 |
status=1
|
797 |
## END
|
798 |
# OK mksh stdout: status=2
|
799 |
## OK mksh stdout-json: ""
|
800 |
|
801 |
|
802 |
|
803 |
case $SH in (dash|ash) return ;; esac # not implemented
|
804 |
|
805 |
# same hanging bug
|
806 |
case $SH in (mksh) return ;; esac
|
807 |
|
808 |
mkdir -p dir
|
809 |
read -n 3 x < ./dir
|
810 |
echo status=$?
|
811 |
## STDOUT:
|
812 |
status=1
|
813 |
## END
|
814 |
## OK mksh stdout-json: ""
|
815 |
## N-I dash/ash stdout-json: ""
|
816 |
|
817 |
|
818 |
case $SH in (dash|ash|mksh|zsh) return ;; esac # not implemented
|
819 |
|
820 |
mkdir -p dir
|
821 |
mapfile $x < ./dir
|
822 |
echo status=$?
|
823 |
|
824 |
## STDOUT:
|
825 |
status=1
|
826 |
## END
|
827 |
## BUG bash STDOUT:
|
828 |
status=0
|
829 |
## END
|
830 |
## N-I dash/ash/mksh/zsh stdout-json: ""
|
831 |
|
832 |
|
833 |
mkdir -p dir
|
834 |
|
835 |
echo foo > ./dir
|
836 |
echo status=$?
|
837 |
printf foo > ./dir
|
838 |
echo status=$?
|
839 |
|
840 |
## STDOUT:
|
841 |
status=1
|
842 |
status=1
|
843 |
## END
|
844 |
## OK dash STDOUT:
|
845 |
status=2
|
846 |
status=2
|
847 |
## END
|
848 |
|