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 ARRAYParameters & Attributes
| Name | Type | Description |
|---|---|---|
| FD | integer | Open input descriptor |
| COUNT | integer | Positive maximum records per call |
| ARRAY | identifier | Trusted 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<&-