builtin-option

Bounded mapfile batches

Read at most COUNT records per call for positive COUNT. A zero count means unlimited input. Test array length for EOF; record length remains unbounded.

Formal Syntax & Structure

bash syntaxbash
mapfile -u FD -n COUNT -t ARRAY

Parameters & Attributes

NameTypeDescription
FDintegerOpen input descriptor
COUNTintegerPositive maximum records per call
ARRAYidentifierTrusted indexed array name

Return Value

exit status

Read at most COUNT records per call for positive COUNT. A zero count means unlimited input. Test array length for EOF; record length remains unbounded.

Working Example

Example Snippetbash
printf '%s\n' a b c d e > input.txtexec 3< input.txtwhile :; do    mapfile -u 3 -n 2 -t batch || exit 1    ((${#batch[@]})) || break    printf 'batch=%s\n' "${#batch[@]}"    printf '%s\n' "${batch[@]}"doneexec 3<&-
Bash Reference