mapfile

The bash 4 builtin, also called readarray, that reads every line of its input into an array in one step.

In more detail

mapfile -t lines < file drops the newline from each element. Feeding it from a redirect or process substitution, not a pipe, keeps the array in the current shell. It is missing from bash 3.2 and POSIX sh.

Example

mapfile -t lines < config.env; echo "${#lines[@]}"

Related terms

Taught in

References