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