Bash Arrays Reading an entire file into an array


Example

Reading in a single step:

IFS=$'\n' read -r -a arr < file

Reading in a loop:

arr=()
while IFS= read -r line; do
  arr+=("$line")
done
4.0

Using mapfile or readarray (which are synonymous):

mapfile -t arr < file
readarray -t arr < file