Bash.Builtin.Mapfile (Bash v0.6.0)

Copy Markdown View Source

mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]

Read lines from the standard input into the indexed array variable ARRAY, or from file descriptor FD if the -u option is supplied. The variable MAPFILE is the default ARRAY.

Options: -d delim Use DELIM to terminate lines, instead of newline. DELIM is a single character. -n count Copy at most COUNT lines. If COUNT is 0, all lines are copied. -O origin Begin assigning to ARRAY at index ORIGIN. The default index is 0. -s count Discard the first COUNT lines read. -t Remove a trailing DELIM from each line read (default newline). -u fd Read lines from file descriptor FD instead of the standard input. -C callback Evaluate CALLBACK each time QUANTUM lines are read. -c quantum Specify the number of lines read between each call to CALLBACK.

If -C is specified without -c, the default quantum is 5000. When CALLBACK is evaluated, it is supplied the index of the next array element to be assigned and the line to be assigned to that element as additional arguments.

If not supplied with an explicit origin, mapfile will clear ARRAY before assigning to it.

mapfile returns successfully unless an invalid option or option argument is supplied, ARRAY is invalid or unassignable, or if ARRAY is not an indexed array.

readarray is a synonym for mapfile.

Reference: https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html Reference: https://cgit.git.savannah.gnu.org/cgit/bash.git/plain/builtins/mapfile.def?h=bash-5.3